duluter
08-04-2009, 11:44 AM
Hi, all.
I recently updated my custom addin file to include a toolbar with one button. I also have set Excel's "At startup, open all files in" setting to point to the folder that contains the addin.
If I launch Excel from the Excel shortcut on my desktop or from the start menu, then my custom addin toolbar loads properly. If I launch Excel by double clicking on an Excel file, Excel launches, the file opens, but my toolbar doesn't load. I just want to know why my toolbar isn't always loading. I am using Excel 2003.
Here is my toolbar code, most of which I cobbled together from resources I found online (this is the first time I've messed with toolbars via VBA).
In my xla's ThisWorkbook module, I have this code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
RemoveBar
If Not bMeClosing Then
Application.OnTime Now, "Createbar"
End If
End Sub
Private Sub Workbook_Open()
CreateBar
End Sub
And in my regular module, I have this code:
'This global variable is used in the ThisWorkbook module.
Public bMeClosing As Boolean
Sub RemoveBar()
On Error Resume Next
Application.CommandBars("xlMyBar").Delete
End Sub
Sub CreateBar()
Dim oBar As CommandBar
Dim oControl As CommandBarButton
RemoveBar
Set oBar = Application.CommandBars.Add
oBar.Name = "xlMyBar"
oBar.Visible = True
oBar.Position = msoBarTop
Set oControl = oBar.Controls.Add(Type:=msoControlButton, ID:=1, Before:=1)
oControl.OnAction = "MyMacro"
oControl.Style = msoButtonCaption
oControl.Caption = "Press Me"
Set oControl = Nothing
Set oBar = Nothing
End Sub
Does this problem have to do with me putting code in the xla's ThisWorkbook module? I'm not really sure how Excel handles code in this module in xla files.
Thanks,
Duluter
UPDATE: After logging off my computer and logging back in, the problem appears resolved. The toolbar now loads whenever Excel is opened. I have no idea what was going on. If anyone has any critiques of my general approach, I'd still be interested to hear, but otherwise the original issue seems to be resolved.
I recently updated my custom addin file to include a toolbar with one button. I also have set Excel's "At startup, open all files in" setting to point to the folder that contains the addin.
If I launch Excel from the Excel shortcut on my desktop or from the start menu, then my custom addin toolbar loads properly. If I launch Excel by double clicking on an Excel file, Excel launches, the file opens, but my toolbar doesn't load. I just want to know why my toolbar isn't always loading. I am using Excel 2003.
Here is my toolbar code, most of which I cobbled together from resources I found online (this is the first time I've messed with toolbars via VBA).
In my xla's ThisWorkbook module, I have this code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
RemoveBar
If Not bMeClosing Then
Application.OnTime Now, "Createbar"
End If
End Sub
Private Sub Workbook_Open()
CreateBar
End Sub
And in my regular module, I have this code:
'This global variable is used in the ThisWorkbook module.
Public bMeClosing As Boolean
Sub RemoveBar()
On Error Resume Next
Application.CommandBars("xlMyBar").Delete
End Sub
Sub CreateBar()
Dim oBar As CommandBar
Dim oControl As CommandBarButton
RemoveBar
Set oBar = Application.CommandBars.Add
oBar.Name = "xlMyBar"
oBar.Visible = True
oBar.Position = msoBarTop
Set oControl = oBar.Controls.Add(Type:=msoControlButton, ID:=1, Before:=1)
oControl.OnAction = "MyMacro"
oControl.Style = msoButtonCaption
oControl.Caption = "Press Me"
Set oControl = Nothing
Set oBar = Nothing
End Sub
Does this problem have to do with me putting code in the xla's ThisWorkbook module? I'm not really sure how Excel handles code in this module in xla files.
Thanks,
Duluter
UPDATE: After logging off my computer and logging back in, the problem appears resolved. The toolbar now loads whenever Excel is opened. I have no idea what was going on. If anyone has any critiques of my general approach, I'd still be interested to hear, but otherwise the original issue seems to be resolved.