VBA运行时错误' 1004':方法' MacroOptions'对象' _Application'失败

时间:2018-06-04 18:58:06

标签: excel vba excel-vba runtime-error

打开启用宏的Excel工作簿(Microsoft Office 365)后,我立即收到此错误。错误窗口有四个按钮: Continue (灰显),结束调试(灰显)和帮助< / KBD>。该工作簿包含一个带有三个简单子例程的模块,其中没有一个使用Application.MacroOptions。以下是模块中的代码:

Sub CopyCMCTab()

On Error GoTo ErrExit
Call SpeedOn

Dim Wb As Workbook
Dim rng As Range
Dim c As Range
Dim facility As String
Dim template As String

Set Wb = Application.ThisWorkbook
Set rng = Wb.Sheets("Ref").Range("FACILITIES[facility]")
template = "CMC"

For Each c In rng 'Loop through all facilities

    If c.Value <> "CMC" Then

        facility = c.Value

        If facility = "CMMC" Then

            If Evaluate("ISREF('" & facility & "'!A1)") Then
                Wb.Sheets(facility).Delete
            End If

            Wb.Sheets(template).Copy after:=Wb.Sheets(Wb.Sheets.Count)
            ActiveSheet.Name = facility

        End If

    End If

Next c

Call SpeedOff
Exit Sub
ErrExit:
MsgBox Err.Description
Call SpeedOff

End Sub

Sub SpeedOn()
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
Application.DisplayAlerts = False
End Sub

Sub SpeedOff()
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.DisplayAlerts = True
End Sub

执行上面的代码后,我没有收到此错误,只有在打开工作簿后才会出现这种错误。我搜索了其他帖子和论坛,但没有一个建议解决了这个问题。

更新:虽然我没有确定此错误的原因,但重新启动后,我第一次打开工作簿时没有出现。但是,在关闭并重新打开工作簿后,错误再次出现。在过去几周内,在不同的工作簿中偶尔会出现此错误。

0 个答案:

没有答案