Initiating a Custom Toolbar

B

Bishop

I have made a custom toolbar to work with a specific spreadsheet. I need the
toolbar to load if the user doesn't have it already. This is what I'm trying
to do:

Private Sub Workbook_Open()

If "Application.Toolbar X exists" Then "do nothing"
Else: Call "procedure to make toolbar"
End If

End Sub

Just need help filling in the correct syntax to make this work.
 
J

Jim Thomlinson

dim cbr as commandbar

on error resume next
set cbr = application.commadbars(x)
on error goto 0

if cbr is nothing then
'open the bar
end if
 
B

Bishop

Same problem. Works if the toolbar isn't already present but if it's there I
get a "Invalid procedure call or element" error. Below is my code:

Private Sub Workbook_Open()

Dim cbr As CommandBar

On Error Resume Next
Set cbr = Application.commadbars("CDToolBar")
On Error GoTo 0

If cbr Is Nothing Then
Call CatalystDumpToolBar
Call AddCustomControl
End If

If ThisWorkbook.Name Like "Master*" Then NotSoFast.Show
End Sub

the above code runs even if the toolbar is present and then goes here:

Sub CatalystDumpToolBar()

Dim CDToolBar As CommandBar

Set CDToolBar = CommandBars.Add(temporary:=True)
With CDToolBar
.Name = "CDToolBar"
.Position = msoBarTop
.Visible = True
End With
End Sub

This is where I get the error: .Name = "CDToolBar".
 
D

Dave Peterson

Maybe it's because you spelled commandbars incorrectly. And the "on error
resume next" line hid that spelling mistake.
 
B

Bishop

That was exactly it! Corrected the spelling and it works now. Thanks for
pointing that out.
 

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