C
Conan Kelly
Hello all,
I have the following code in a class module 'EventClass' in my
personal macro workbook so it will run each time a new file is opened:
Public WithEvents App As Application
Private Sub App_WorkbookOpen(ByVal Wb As Workbook)
If Application.Calculation = xlCalculationAutomatic Then
' Application.Calculation = xlCalculationManual
' Application.CalculateBeforeSave = False
Application.CommandBars("My Toolbar").Controls(2).Caption =
"AutoCalc On"
Application.CommandBars("My Toolbar").Controls("AutoCalc
On").TooltipText = "Turns AutoCalc Off"
' MsgBox "AutoCalc is now OFF.", vbInformation, "AutoCalc
Status"
Else
' Application.Calculation = xlCalculationAutomatic
' Application.CalculateBeforeSave = True
Application.CommandBars("My Toolbar").Controls(2).Caption =
"AutoCalc Off"
Application.CommandBars("My Toolbar").Controls("AutoCalc
Off").TooltipText = "Turns AutoCalc On"
' MsgBox "AutoCalc is now ON.", vbInformation, "AutoCalc
Status"
End If
End Sub
The problem I am having is if I open Excel normally (standard Excel
shortcut in start menu etc. with a new blank workbook), I get no
errors. But if I open Excel by dbl clickin an Excel file, I get a
'Type mismatch' error. Also, I get this same error if I open Excel
with the /e switch (no splash screen & no workbook opened--this is the
preferred way, I'd like to put this in my 'Startup' folder in my Start
menu).
Is there a way I can modify this so I won't get the error when opening
Excel the two problematic ways described above?
Thanks for any help anyone can provide,
Conan Kelly
I have the following code in a class module 'EventClass' in my
personal macro workbook so it will run each time a new file is opened:
Public WithEvents App As Application
Private Sub App_WorkbookOpen(ByVal Wb As Workbook)
If Application.Calculation = xlCalculationAutomatic Then
' Application.Calculation = xlCalculationManual
' Application.CalculateBeforeSave = False
Application.CommandBars("My Toolbar").Controls(2).Caption =
"AutoCalc On"
Application.CommandBars("My Toolbar").Controls("AutoCalc
On").TooltipText = "Turns AutoCalc Off"
' MsgBox "AutoCalc is now OFF.", vbInformation, "AutoCalc
Status"
Else
' Application.Calculation = xlCalculationAutomatic
' Application.CalculateBeforeSave = True
Application.CommandBars("My Toolbar").Controls(2).Caption =
"AutoCalc Off"
Application.CommandBars("My Toolbar").Controls("AutoCalc
Off").TooltipText = "Turns AutoCalc On"
' MsgBox "AutoCalc is now ON.", vbInformation, "AutoCalc
Status"
End If
End Sub
The problem I am having is if I open Excel normally (standard Excel
shortcut in start menu etc. with a new blank workbook), I get no
errors. But if I open Excel by dbl clickin an Excel file, I get a
'Type mismatch' error. Also, I get this same error if I open Excel
with the /e switch (no splash screen & no workbook opened--this is the
preferred way, I'd like to put this in my 'Startup' folder in my Start
menu).
Is there a way I can modify this so I won't get the error when opening
Excel the two problematic ways described above?
Thanks for any help anyone can provide,
Conan Kelly