运行时错误“ 50290”:打开Excel工作簿时,应用程序定义或对象定义的错误

时间:2019-04-18 21:37:54

标签: excel access-vba

有关此主题的问题很多,但没有有效的解决方案。

这是我的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)

考虑:

  • 该文件已关闭
  • 没有打开Excel文件
  • 在任务管理器中没有任何EXCEL.EXE任务在运行

0 个答案:

没有答案