带功能区的工作簿不断崩溃Excel

带功能区的工作簿不断崩溃Excel,excel,vba,Excel,Vba,我有一个相当大的工作簿和一个非常复杂的VBA项目 工作簿还具有自定义功能区 工作簿_Open事件中也发生了很多事情,比如取消保护和重新保护userInterfaceOnly、隐藏和显示各种工作表、存储对功能区的引用等 当宏未自动启用时,工作簿将打开,并显示“启用”按钮,当我单击该按钮时,一切都会正常进行 当文件受信任且宏自动运行时,就会出现问题。在这些情况下,它有使应用程序崩溃的趋势 这就好像,如果用户必须单击按钮时出现暂停,它会完成所有Excel准备工作,显示功能区,然后执行所有“我的工作簿打

我有一个相当大的工作簿和一个非常复杂的VBA项目

工作簿还具有自定义功能区

工作簿_Open事件中也发生了很多事情,比如取消保护和重新保护userInterfaceOnly、隐藏和显示各种工作表、存储对功能区的引用等

当宏未自动启用时,工作簿将打开,并显示“启用”按钮,当我单击该按钮时,一切都会正常进行

当文件受信任且宏自动运行时,就会出现问题。在这些情况下,它有使应用程序崩溃的趋势

这就好像,如果用户必须单击按钮时出现暂停,它会完成所有Excel准备工作,显示功能区,然后执行所有“我的工作簿打开”操作,但是如果没有“启用”按钮,Excel自己的启动操作和显示功能区似乎会与“我的工作簿打开”事件纠缠在一起,导致崩溃

这种情况发生在2007年、2010年和2013年以及windows 7和8.1上

我怀疑这与功能区有关,因为有时问题不是完全崩溃,而是工作簿打开,功能区区域为空

仅供参考工作簿\u打开事件中的代码如下所示:

enter code here
Private Sub Workbook_Open()
Dim newHour As Single
Dim newMinute As Single
Dim newSecond As Single
Dim waitTime As Date

    Application.ScreenUpdating = False
'   To activate the ribbon in v2007
    Application.SendKeys "%Q{RETURN}"

    Call ResetTheSheets

    Splash.Visible = xlSheetVisible
    Splash.Protect shtHidden.Range("iWord")
    Call ShowHideSplash

    ExecSumm.Visible = xlSheetVisible
    GetStarted.Visible = xlSheetVisible
'   Look at the properties in the Prop sheet to see what should be displayed
    If Prop.Range("PropHideGetStarted") Then

On Error Resume Next
        With ExecSumm
            .Activate
            'Range("C4").Select
            .Unprotect Password:=shtHidden.[iWord]
            .Visible = xlSheetVisible
            .Range("A1:A" & .Range("LastRowCol").Row).EntireRow.Hidden = False
            .Range(.Cells(1, 1), .Cells(1, .Range("LastRowCol").Column)).EntireColumn.Hidden = False
'           Check to see if the template column has anything in
            If WorksheetFunction.CountA(.Range("TemplateCol")) = 0 Then .Range("TemplateCol").EntireColumn.Hidden = True
'           Check to see if the prior year should be hidden
            If Not Prop.Range("PropBFbalances") Then .Range("ppTitle").EntireColumn.Hidden = True
            .Activate
        End With
    Else
        GetStarted.Select
    End If
    ActiveWindow.ScrollRow = 1

FormShow:
Err.Clear
On Error GoTo FormShow
    frmSplash.Show msoFalse

    shtHidden.Range("iBalance") = "TRUE"
'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
''   Schedule the start to avoid 'startup-crashes' - this didn't work as a way to prevent
'    newHour = Hour(Now())
'    newMinute = Minute(Now())
'    newSecond = Second(Now()) + 1
'    waitTime = TimeSerial(newHour, newMinute, newSecond)
'    Application.Wait waitTime
'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Err.Clear
On Error GoTo 0
    Application.OnTime Now + TimeValue("00:00:01"), "StartUpMacro"
End Sub
你可以尝试:

a。根据您的需要,让excel在sendkey事件之前或之后等待预定义的时间准备就绪:

Application.Wait(Now + #0:00:05#)      '5 sec for example 
礼节:

b。使用msgbox弹出类似于宏启用按钮的窗口,以禁止快速执行其余代码。

是否尝试将所有打开的代码移动到StartUpMacro例程?