0

我正在尝试使用此代码打开一个 csv 文件,但它一直给我一个“错误 52 错误文件名或编号”

 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

调试器突出显示 Open for X 行,但我将路径名作为字符串提供给它

4

1 回答 1

1

将此行直接添加到导致错误的行之前:

FF1 = FreeFile

因为 Open For Input 需要 1 到 512 之间的数字,应该通过调用FreeFile来获得。

于 2012-10-12T14:49:47.883 回答