2012-10-12 118 views
0

我試圖用這個代碼打開一個CSV文件,它不斷給我一個「錯誤52錯誤的文件名或號碼」打開一個csv用Excel VBA

Sub ShowFileDialog() 
    Dim x As String 
    Dim FF1 As Integer 
    Dim dlgOpen As FileDialog 
    Set dlgOpen = Application.FileDialog(_ 
     msoFileDialogFilePicker) 
    With dlgOpen 

     .Show 
    End With 

x = CStr(dlgOpen.SelectedItems(1)) 
MsgBox x 

Open x For Input As #FF1 

Do While Not EOF(FF1) 

Line Input #FF1, inputdata 

Dim lineData() As String 
lineData() = Split(inputdata, ",") 



Loop 
Close #FF1 
End Sub 

調試器是突出開放的X線但我餵養它的路徑名字符串

+1

您從未將FF1設置爲文件編號。開幕之前'FF1 = FreeFile'。 – Jacob

回答

1

前行直接添加此行會導致錯誤:

FF1 = FreeFile 

由於Open輸入需要1和512之間的數字,這應該是OBTA通過撥打電話FreeFile