我在尝试将 dbf 文件读取到我的 VBA 宏时遇到问题,通过它,处理数据并放入选择的工作表中。我被卡住了,因为我收到 3001 错误(参数类型错误、超出范围或冲突)
这是我的代码,它可能有什么问题?
FileToOpen = Application.GetOpenFilename _
(Title:="Please choose a file to import", _
FileFilter:="Excel Files *.dbf (*.dbf),")
''
If FileToOpen = False Then
MsgBox "Plik nie został wybrany.", vbExclamation, "Błąd!"
Exit Sub
Else
Dim conn As Object
Set conn = CreateObject("ADODB.Connection")
Dim rst As Object
Set rst = CreateObject("ADODB.Recordset")
iPos = InStrRev(FileToOpen, "\", , vbTextCompare)
Filepath = Left(FileToOpen, iPos)
Filename = Right(FileToOpen, iPos - 1)
MsgBox Filename & " " & Filepath
conn.Open "DRIVER={Microsoft dBase Driver (*.dbf)};" & "DBQ=" & Filepath
Debug.Print conn.ConnectionString
rst.Open "Select * From " & Filename, conn, adOpenStatic, adLockReadOnly, adCmdText
Do Until rst.EOF
Debug.Print rst.Fields(1).Value
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
conn.Close
Set conn = Nothing
End If
我还检查了一个文件格式,它是“没有 DBT 的文件”,不管它是什么意思,仍然不知道它的格式:> 也许我应该更改驱动程序 ID?