我正在尝试连接到硬盘上的excel文件,但我一直收到以下错误
这是我的代码:
Public Sub excelConnection()
Dim strConnection As String
Dim strCommand As String
Dim excelPath As String
Dim vsoDataRecordset As Visio.DataRecordset
excelPath = "G:\data\info.xlsx"
strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" _
& "User ID=Admin;" _
& "Data Source=" + excelPath _
& "Mode=Read;" _
& "Extended Properties=""HDR=NO;IMEX=1;MaxScanRows=0;Excel 12.0;"";" _
& "Jet OLEDB:System database="""";" _
& "Jet OLEDB:Registry Path="""";" _
& "Jet OLEDB:Engine Type=37;" _
& "Jet OLEDB:Database Locking Mode=0;" _
& "Jet OLEDB:Global Partial Bulk Ops=2;" _
& "Jet OLEDB:Global Bulk Transactions=1;" _
& "Jet OLEDB:New Database Password="""";" _
& "Jet OLEDB:Create System Database=False;" _
& "Jet OLEDB:Encrypt Database=False;" _
& "Jet OLEDB: Don 't Copy Locale on Compact=False;" _
& "Jet OLEDB:Compact Without Replica Repair=False;" _
& "Jet OLEDB:SFP=False;" _
& "Jet OLEDB:Support Complex Data=False;" _
& "Jet OLEDB:Bypass UserInfo Validation=False;" _
& "Jet OLEDB:Limited DB Caching=False;" _
& "Jet OLEDB:Bypass ChoiceField Validation=False"
strCommand = "select * from `straight-x-z$E3:F6`"
Set vsoDataRecordset = ActiveDocument.DataRecordsets.Add(strConnection, strCommand, 0, "Points")
End Sub
答案 0 :(得分:1)
我终于以这种方式工作了。这是我的VBA代码。希望这可以帮助。我使用了引擎类型34
strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" + _
"User ID=Admin;" + _
"Data Source="+ srcLocation + _
"Mode=Read;" + _
"Extended Properties=""HDR=YES;IMEX=1;MaxScanRows=0;Excel 12.0;"";" + _
"Jet OLEDB:Engine Type=34;"
strCommand = "Select * from `SHEETNAME$`"
Set vsoDataRecordset = Visio.ActiveDocument.DataRecordsets.Add(strConnection, strCommand, 0, "DATA")