Hi
I've written a macro that will delete a toolbar button and two other toolbars.
Problem is, if one (or more) of the toolbars doesn't exist I get an error:
Yet I've added in 'On Error Goto' statements to avoid errors!
So, if the toolbar exists, the macro deletes it - all good. But if it doesn't I get a compile-time error. What gives?
JJ
I've written a macro that will delete a toolbar button and two other toolbars.
Problem is, if one (or more) of the toolbars doesn't exist I get an error:
Code:
Run-time error '5':
Invalid procedure call or argument
Yet I've added in 'On Error Goto' statements to avoid errors!
Code:
Sub Main()
'
' AutoExec Macro
' Macro created 31/05/2006 by JefferyJ
'
Delete1:
On Error GoTo ErrorMessage1
CommandBars("Standard").Controls("CORP").Delete
msg = "CORP Toolbar button deleted"
Delete2:
On Error GoTo ErrorMessage2
CommandBars("CORP Reports").Delete
msg = msg & Chr(10) & "CORP Reports Toolbar deleted"
Delete3:
On Error GoTo ErrorMessage3
CommandBars("CORP Styles").Delete
msg = msg & Chr(10) & "CORP Styles Toolbar deleted"
GoTo TheEnd
ErrorMessage1:
msg = "No CORP Toolbar button found!"
GoTo Delete2
ErrorMessage2:
msg = msg & Chr(10) & "No CORP Reports Toolbar found!"
GoTo Delete3
ErrorMessage3:
msg = msg & Chr(10) & "No CORP Styles Toolbar found!"
TheEnd:
MsgBox (msg)
End Sub
So, if the toolbar exists, the macro deletes it - all good. But if it doesn't I get a compile-time error. What gives?
JJ