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
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