.txt 파일에서 데이터를 읽은 다음 .xls 파일에 데이터를 채우는 데 사용하려고하지만, .txt 파일을 연 후 어떻게 데이터를 가져 옵니까? 기본적으로 '04/06/2010 '일자의 세 번째 열을 얻으려고합니다. 을 사용할 때 .txt 파일을 열면 ActiveSheet
이 .txt 파일을 가리키고 있지 않습니다.VBA에서 .txt 파일의 데이터를 Excel로 채우는 방법?
내 .txt 파일은 (공간 분리) 이렇게 있습니다 :
여기04/05/10 23 29226
04/05/10 24 26942
04/06/10 1 23166
04/06/10 2 22072
04/06/10 3 21583
04/06/10 4 21390
코드 나는이된다
Dim BidDate As Date
BidDate = '4/6/2010'
Workbooks.OpenText Filename:=ForecastFile, StartRow:=1, DataType:=xlDelimited, Space:=True
If Err.Number = 1004 Then
MsgBox ("The forecast file " & ForecastFile & " was not found.")
Exit Sub
End If
On Error GoTo 0
Dim row As Integer, col As Integer
row = 1
col = 1
cell_value = activeSheet.Cells(row, col)
MsgBox ("the cell_value=" & cell_value)
Do While (cell_value <> BidDate) And (cell_value <> "")
row = row + 1
cell_value = activeSheet.Cells(row, col)
' MsgBox ("the value is " & cell_value)
Loop
If cell_value = "" Then
MsgBox ("A load forecast for " & BidDate & " was not found in your current load forecast file titled '" + ForecastFile + ". " + "Make sure you have a load forecast for the current bid date and then open this spreadsheet again.")
ActiveWindow.Close
Exit Sub
End If
사람이 여기에 잘못 곳을 포인트?
형식을 변경 아래 그 I를 추가해야 코드에 오류가 발생하지 않았으므로 아무 것도하지 않는 것 같습니다. –