command bar name not recognized

S

salgud

I've cobbled together the following code to create a toolbar everytime a
certain spreadsheet opens:

Sub CreateOSIMenubar()

Dim vMacNames As Variant
Dim vCapNames As Variant
Dim vTipText As Variant

Call RemoveOSIMenubar

vMacNames = "OSILogInsertRow"
vCapNames = "OSILogInsertRow"
vTipText = "Add Row"

With Application.CommandBars
.Add
.Name = vMacNames <----- Compile Error: Method or Data Member not found
.Left = 200
.Top = 200
.Protection = msoBarNoProtection
.Visible = True
.Position = msoBarTop
.Left = CommandBars("FormatDGB").Left + CommandBars("FormatDGB").Width
.RowIndex = CommandBars("FormatDGB").RowIndex
End With
With CommandBars(vMacNames).Controls.Add(Type:=msoControlButton)
.OnAction = "'" & ThisWorkbook.Name & "'!" & vMacNames
.Caption = vCapNames
.Style = msoButtonCaption
.TooltipText = vTipText
End With
End Sub

Doesn't recognize the name variable or something. Any ideas?
Thanks
 
G

Gord Dibben

With Application.CommandBars.Add
.Name = vMacNames
'rest of stuff


Gord Dibben MS Excel MVP
 
S

salgud

With Application.CommandBars.Add
.Name = vMacNames
'rest of stuff
Thanks for the reply, Gord. When I try that, I get a "Invalid or
unqualified reference" error on that same lime. Any ideas?
 
S

salgud

Thanks for the reply, Gord. When I try that, I get a "Invalid or
unqualified reference" error on that same lime. Any ideas?

My mistake, error message is "Invalid procedure call or reference"
 
G

Gord Dibben

Can you post the removeosimenubar code?

That is probably throwing an error when you try to remove a bar that does
not yet exist.

With my limited skills I don't see what these two lines do.

..Left = CommandBars("FormatDGB").Left + CommandBars("FormatDGB").Width
.RowIndex = CommandBars("FormatDGB").RowIndex

Maybe you have to wrap them inside their own With...........End With


Gord
 
S

salgud

Can you post the removeosimenubar code?

That is probably throwing an error when you try to remove a bar that does
not yet exist.
That fixed it! Thanks, Gord.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top