重新启动后出现错误1004:此工作簿中可能无法使用宏,或者可能禁用所有宏

时间:2015-08-20 10:51:21

标签: vba excel-vba runtime-error excel

我正在运行一个宏,打开另一个excel文件(.xlsm)并运行该文件中包含的宏。

我重新启动了我的电脑并尝试运行它。但代码不再起作用并显示此错误:

  

运行时错误1004 :无法运行宏'01 .xlsm!ReadCheckBoxes1'。

     

此工作簿中可能无法使用该宏,或者可能禁用所有宏。

当它到达此行时出现错误

Call Application.Run(Macro1)

启用所有宏,信任中心勾选“信任访问VBA项目对象模型”

完整的代码如下,你能帮帮我吗?

Sub FileAnalysis()

    Dim File As String
    Dim Path As String

    Dim Macro1 As String
    Dim Macro2 As String

    Dim b As Object

    Dim Ligne As Integer

    Dim wb As Workbook


    Set b = ThisWorkbook.Worksheets(7).Buttons(Application.Caller)

        With b.TopLeftCell
            Ligne = .Row
        End With

    Application.ScreenUpdating = False


    File = ThisWorkbook.Worksheets(7).Cells(Ligne, "B").Text
    ThisWorkbook.Worksheets(7).Cells(4, 9) = File 'debug

    Path = ActiveWorkbook.Path
    ThisWorkbook.Worksheets(7).Cells(4, 10) = Path 'debug

    If Dir(Path & "\" & File) = "" Then
        MsgBox "File doesn't exist."
    Else
        Set wb = Workbooks.Open(Path & "\" & File)
        ActiveWorkbook.Worksheets(6).Unprotect ("test")
        Macro1 = File & "!" & "ReadCheckBoxes1"
        Macro2 = File & "!" & "ReadCheckBoxes2"
        ThisWorkbook.Worksheets(7).Cells(3, 10) = ActiveWorkbook.Name 'debug
        ThisWorkbook.Worksheets(7).Cells(4, 11) = Macro1 'debug
        ThisWorkbook.Worksheets(7).Cells(4, 12) = Macro2 'debug

        Call Application.Run(Macro1) 'error displayed here
        Call Application.Run(Macro2) 'error displayed here if I comment the previous line
        wb.Close SaveChanges:=True

        ThisWorkbook.Worksheets(7).Cells(Ligne, 4) = "Yes"
        ThisWorkbook.Worksheets(7).Cells(4, 13) = "Done"

        Application.DisplayFormulaBar = True
        ActiveWindow.DisplayWorkbookTabs = True
        ActiveWindow.DisplayHeadings = True
        ActiveWindow.DisplayGridlines = True
    End If

    Application.ScreenUpdating = True

    If Application.CommandBars("Ribbon").Height <= 100 Then
        CommandBars.ExecuteMso "MinimizeRibbon"
    End If

    Set wb = Nothing
    Set b = Nothing

End Sub

1 个答案:

答案 0 :(得分:0)

我不知道发生了什么,但关闭笔记本电脑后(正常关机)一切都开始恢复了。

重启不起作用(我尝试了3次),但关闭然后再开启确实让它再次起作用。

相关更改是在继续之前开始显示以下警告:

&#34;隐私警告:本文档包含宏,ActiveX控件,XML扩展包信息或Web组件。这些可能包括文档检查员无法删除的个人信息&#34;

如果有人对可能发生的事情有所了解,那就太棒了。

欢呼声