RonBonBon


Hi

I have added a CommandBarButton to my excel workbook.

My question is how can i make it load with my workbook (i mean when i open my file)

Thank's.

My code sample is:

Dim cb As CommandBar
Dim b As CommandBarButton

Set cb = Application.CommandBars("Standard")

Set b = cb.Controls.Add(msoControlButton, , , , True)
b.Caption = "Hello"
b.FaceId = 234
b.Style = msoButtonIconAndCaption
b.OnAction = "Test"




Re: Excel 2003 CommandBarButton

Keithyboy1


Can you not copy the above code into an Open event handler for the workbook

Private Sub Workbook_Open()

Dim cb As CommandBar
Dim b As CommandBarButton

Set cb = Application.CommandBars("Standard")

Set b = cb.Controls.Add(msoControlButton, , , , True)
b.Caption = "Hello"
b.FaceId = 234
b.Style = msoButtonIconAndCaption
b.OnAction = "Test"

End Sub






Re: Excel 2003 CommandBarButton

RonBonBon

I tried that and it didn't work.

I want that the code I wrote, the one that create the CommandBarButton, will run when the file is opened.

And that will lead to the creation of the CommandBarButton.






Re: Excel 2003 CommandBarButton

Keithyboy1

After copying your code into a Workbook_Open event handler, it successfully added a button to my toolbar upon opening the file.

Isn't that what you wanted to happen





Re: Excel 2003 CommandBarButton

RonBonBon

Thank you for your answer,

At first I didn't understand the part about the Workbook_Open event handler.

But now I understand that.