有关此主题的问题很多,但没有有效的解决方案。
这是我的Access VBA代码。
Dim fDialog As Object
Set fDialog = Application.FileDialog(3)
Dim excelPath As String
excelPath = ""
With fDialog
.Title = "Carica da Template"
.AllowMultiSelect = False
.Filters.Clear
If .Show = True Then
If .SelectedItems.Count > 0 Then
excelPath = .SelectedItems(1)
End If
End If
End With
If Len(excelPath) = 0 Then
GoTo Cerca_Exit
End If
Set fDialog = Nothing
Dim sql As String
sql = "DELETE FROM [Pianificazione Risorse];"
DoCmd.RunSQL sql
Dim mExcel As Object
Set mExcel = CreateObject("Excel.Application")
Dim mBook As Object
Set mBook = mExcel.Workbooks.Open(excelPath, readonly:=True)
mExcel.Visible = False
Dim mSheet As Object
Set mSheet = mBook.Worksheets(1)
我正在打开一个对话框以加载Excel文件,但此时出现该错误:
设置mBook = mExcel.Workbooks.Open(excelPath,只读:= True)
考虑: