chapter 10 problem
In chapter 10 I try to create the command bar and everything in code seems fine but when I run it I get the error message: run time error 5, invalid procedure call or argument. I have also added the office 11 object library. Can someone suggest a solution?
Sub CreateCommandBar()
Dim cbReport As CommandBar
Dim btnButton As CommandBarButton
'delete the command bar and if it does not exist, continue
On Error Resume Next
CommandBars("Wrox1 Report").Delete
On Error GoTo 0
'add the new command bar to the collection
Set cbReport = CommandBars.Add("Wrox1 Report", msoBarFloating)
'add Zoom button to the toolbar
Set btnButton = cbReport.Controls.Add(msoControlButton, _
CommandBars("Print Preview") _
.Controls("Zoom").Id)
'add 2 pages button to the toolbar
Set btnButton = cbReport.Controls.Add(msoControlButton, _
CommandBars("Print Preview") _
.Controls("Two Pages").Id)
'add copy button to the toolbar
Set btnButton = cbReport.Controls.Add(msoControlButton, _
CommandBars("Database") _
.Controls("Copy").Id)
'add a custom button to the toolbar
Set btnButton = cbReport.Controls.Add(msoControlButton)
btnButton.Caption = "Test Button"
btnButton.Style = msoButtonCaption
'list the name of the procedure to call when the button is clicked
btnButton.OnAction = "DisplayMessage"
'display the new command bar by setting visible
cbReport.Visible = True
End Sub
Sub DisplayMessage()
MsgBox "The new button was clicked."
End Sub
|