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!

Error removing Excel toolbar button in macro

Status
Not open for further replies.

cg084

Technical User
May 3, 2002
67
GB
Hello,

I have added a button on to a toolbar in excel through the use of a macro. I would like to remove just this one button from the curtom toolbar. I have used the following code to create the button on the toolbar and the second sub is to remove the button when clicked.

Sub CloseValidationPauseToolbar()

Dim NewBar As Object
Set NewBar = CommandBars("Inbound Attendance Sheets")
With NewBar
.Controls.Add Type:=msoControlButton, ID:=1, before:=3
With .Controls(3)
.Style = msoButtonCaption
.Caption = "Continue Processing"
.OnAction = "ValidationComplete"
End With
End With

End Sub
-----------------------------------------------------------
Sub ValidationComplete()

Application.CommandBars("Inbound Attendance Sheets").Controls(3).Delete
Call RunAllMacros

End Sub
-----------------------------------------------------------

When i run the ValidationComplete sub i receive this error message.

Run-time error '-2147467259(80004005)':
Method 'Delete' of ofbject '_CommandBarButton' failed.

It is strange that at this point if i end the sub. The run through line by line it appears to work fine.

Does anyone have any ideas on this.
Thank you
CG084

 
Hi CG,

Actually, I'm surprised that it doesn't fail at:
.Controls.Add Type:=msoControlButton, ID:=1, before:=3
since there don't appear to be anything at 1 & 2 to put this one before.

Cheers
 
macropod,

You spotted that. I forgot to mention that this toolbar allready has 2 buttons on it. So when the above subs run it should add it after them.

Cheers CG084
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top