我有一些代码允许我选择一个必需的Excel文件导入到Access中的表。
此代码在Windows XP,Access 2003中运行良好。全新安装的Windows 7并将Office 2013 Professional安装到PC,现在相同的代码不起作用。 Access给我一个运行时错误91:对象变量或没有设置块。
Dim xlApp As Object
Dim txt As String
Dim myRow As Long
Dim rs As Recordset
Dim filename As String
Dim sql As String
CommonDialog1.filename = "" -> Code fails here
CommonDialog1.showOpen
If Len(CommonDialog1.filename) < 3 Then Exit Sub
Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Open filename:=CommonDialog1.filename
我在一些使用Office 2013,Windows 7在桌面上运行的用户PC上尝试了这个代码。 VBA和Access开发相当新,所以不确定是什么引起了这个问题。
感谢帮助。