View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Creating a Toolbar with a macro

David,

I guess the problem must be in some other code. I have tried it half a dozen
times (XP Pro, XL2000) and it works every time.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"DavidP" wrote in message
...
I have the following code which should create a command bar and add 17
buttons. I shortened the example to 3 buttons to save readers time.

Sub Workbook_Open()

'Delete CommandBar if it exists
On Error Resume Next
CommandBars("DataEntry").Delete
On Error GoTo 0

CommandBars.Add Name:="DataEntry"

With
Application.CommandBars("DataEntry").Controls.Add( temporary:=True)
.Caption = "Anti Virus"
.OnAction = "PasteAntiVirus"
End With

With
Application.CommandBars("DataEntry").Controls.Add( temporary:=True)
.Caption = "Audio"
.OnAction = "PasteAudio"
End With

With
Application.CommandBars("DataEntry").Controls.Add( temporary:=True)
.Caption = "Backup"
.OnAction = "PasteBackup"
End With

End Sub

When I open the spreadsheet the macro stops at the line

CommandBars.Add Name:="DataEntry"

The error message is "Run Time error '91' Object Variable ot With
Block Variable not set

I have looked through previous postings but none seem relevant to my
problem. The macro runs when I open the spreadsheet. My XL version
is 2000 running on Win98.

Can anyone point me in the right direction please

David P