Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I test the existence of a Command Bar 1

Status
Not open for further replies.

DLG0311

Technical User
Jan 6, 2005
13
GB
I know how to add a Command Bar and populate it, but I can't seem to crack how to test that the Command Bar exists before either creating it or, when the document is finished with, deleting it.

What would my opening line(s) be in the following code to check this before completing the rest of the macro or ending.

Sub AutoOpen()
If CommandBars("Invoice Request") = True Then Exit Sub
Set cbar1 = CommandBars.Add(Name:="Invoice Request", Position:=msoBarTop)
cbar1.Visible = True
Set oldControl = cbar1.Controls.Add(Type:=msoControlButton)
With oldControl
.Style = msoButtonCaption
.Caption = "Invoice Request"
.FaceId = 204
.OnAction = "Filler"
.TooltipText = "Run Invoice Request Filler"
End With
End Sub
Sub AutoClose()
CommandBars("Invoice Request").Delete
End Sub
 
Hi DLG0311,

The easiest way is to use error trapping ..

Code:
[blue]On Error Resume Next
If CommandBars("Invoice Request") is nothing Then Exit Sub
On error goto 0[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top