PDA

View Full Version : Add toolbar on workbook open



Djblois
05-30-2007, 11:55 AM
I am creating a macro to add a toolbar when a user opens a particular workbook. this is the code I am using but it keeps telling me object variable or with variable is not set. Here is the code I am using:

Private Sub Workbook_Open()
Dim Tbar As CommandBar
Dim newBtn As CommandBarButton
Set Tbar = CommandBars.Add 'This is where I get the error
With Tbar
.Name = "Add_New_Contract"
.Visible = True
.Position = msoBarFloating
End With

Set newBtn = Tbar.Controls.Add(Type:=msoControlButton)
newBtn.OnAction = "AddNewContract"
newBtn.Style = msoButtonCaption
newBtn.Caption = "Add New Contract"
End Sub

Bob Phillips
05-30-2007, 12:24 PM
You have to set the Name argument.

Djblois
05-30-2007, 12:35 PM
xld,

Where do I or how do I set the name argument because nothing is calling for an argument here?

Charlize
05-30-2007, 12:40 PM
Set Tbar = CommandBars.Add(Name:="Add_New_Contract", _
Position:=msoBarFloating, temporary:=True)

Djblois
05-31-2007, 06:10 AM
I am using this:

Set Tbar = CommandBars.Add(Name:="Add_New_Contract", _
Position:=msoBarFloating, temporary:=True)

and at the moment I get the same error message

Bob Phillips
05-31-2007, 06:25 AM
No problems here.