我正在运行一个宏,该宏打开另一个excel文件(.xlsm)并运行该文件中包含的宏。
我重新启动电脑并尝试运行它,但代码不再工作,并显示以下错误:
运行时错误1004:无法运行宏“01.xlsm!ReadCheckBoxes 1”。
宏可能在此工作簿中不可用,或者所有宏都被禁用。
当它到达这一行时出现错误
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
2条答案
按热度按时间bzzcjhmw1#
我不知道发生了什么事,但在关闭笔记本电脑(适当的开关关闭)一切又开始工作了。
重新启动不起作用(我试了3次),但关闭和打开确实使它再次工作。
相关变更是在继续之前开始显示以下警告:
“隐私警告:此文档包含宏、ActiveX控件、XML扩展包信息或Web组件。其中可能包含文档检查器无法删除的个人信息
如果有人知道可能发生了什么,那就太棒了。
干杯
4szc88ey2#
我遇到了这个问题,并通过删除所有下划线和破折号从文件名根据ChipsLetten的评论上面的工作簿和它的工作。