ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   commandbars.add problem (https://www.excelbanter.com/excel-programming/398811-commandbars-add-problem.html)

Billy B

commandbars.add problem
 
I have the following code to create a toolbar on the fly in an Excel 2002
workbook. When I try to run it I get a Runtime error '5' Invalid procedure
call or argument. I have compared my code with the text I have and can't find
anything wrong. Thank you.

Public Sub CreateTheToolbar()
Dim TBar As CommandBar
'************ next line errors out
Set TBar = CommandBars.Add(Name:="Call")
With TBar
.Position = msoBarBottom
.Visible = True
End With

AddButton
End Sub
Private Sub AddButton()
Set NewBtn1 = CommandBars("Call").Controls.Add(Type:=msoControlB utton)
Set NewBtn2 = CommandBars("Call").Controls.Add(Type:=msoControlB utton)
Set newbtn3 = CommandBars("Call").Controls.Add(Type:=msoControlB utton)

With NewBtn1
.FaceId = 41
.OnAction = "HideInstructor"
.Caption = "Hide Instructors"
End With

With NewBtn2
.FaceId = 39
.OnAction = "Show Instructors"
.Caption = "Show Instructors"
End With

With newbtn3
.FaceId = 31
.OnAction = "PrintIt"
.Caption = "Print Callout"
End With


End Sub


Billy B

commandbars.add problem
 
I found that I had not deleted the toolbar on close so. Thanks.

"Billy B" wrote:

I have the following code to create a toolbar on the fly in an Excel 2002
workbook. When I try to run it I get a Runtime error '5' Invalid procedure
call or argument. I have compared my code with the text I have and can't find
anything wrong. Thank you.

Public Sub CreateTheToolbar()
Dim TBar As CommandBar
'************ next line errors out
Set TBar = CommandBars.Add(Name:="Call")
With TBar
.Position = msoBarBottom
.Visible = True
End With

AddButton
End Sub
Private Sub AddButton()
Set NewBtn1 = CommandBars("Call").Controls.Add(Type:=msoControlB utton)
Set NewBtn2 = CommandBars("Call").Controls.Add(Type:=msoControlB utton)
Set newbtn3 = CommandBars("Call").Controls.Add(Type:=msoControlB utton)

With NewBtn1
.FaceId = 41
.OnAction = "HideInstructor"
.Caption = "Hide Instructors"
End With

With NewBtn2
.FaceId = 39
.OnAction = "Show Instructors"
.Caption = "Show Instructors"
End With

With newbtn3
.FaceId = 31
.OnAction = "PrintIt"
.Caption = "Print Callout"
End With


End Sub



All times are GMT +1. The time now is 05:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com