I create and load a commandbar, prior to loading it I attempt to check if it exists, then delete it, and recreate.
I dont understand why this seemed to work for months and now creates an error.
It appears that every now and then the created commandbar is not created when I open a file. Thats when the error pops up. I can manually run the Create_Bar sub and it will be fine, for a while.
Run-time error '5':
Invalid procedure call or argument
This section is in my personal.xls file in "ThisWorkBook" of personal.xls.
'Add to "ThisWorkBook" in Personal.xls or other excel file
'===============================
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call AddToolBar.Delete_Bar
End Sub
Private Sub Workbook_Open()
Call AddToolBar.Create_Bar
End Sub
'===============================
This section is a module (AddToolBar) in personal.xls
Option Explicit
Sub Create_Bar()
Dim MyBar As CommandBar
Dim MyPopup As CommandBarPopup
Dim MyButton As CommandBarButton
On Error Resume Next '10.30.09
Set MyBar = CommandBars.Add(Name:="Custom Menu", _
Position:=msoBarTop, temporary:=True)
'Create commnadbar here
'code removed to save space
End Sub
Sub Delete_Bar()
Dim cbExists As Boolean
cbExists = False
On Error Resume Next
cbExists = Application.CommandBars("Custom Bar").Name = "Custom Menu"
On Error GoTo 0
If cbExists Then
CommandBars("Custom Menu").Delete
Else
End If
End Sub
Code in red is where the error occurrs.
p.s.
This has been happening before today, Friday the 13th, so I dont think its that.
Bookmarks