ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Creating toolbar macro errors (https://www.excelbanter.com/excel-programming/382897-creating-toolbar-macro-errors.html)

Jason Morin

Creating toolbar macro errors
 
Hello. Below is some Dave Peterson code that I found (and modified). I simply
want to create a floating toolbar with one button for my macro. However,
whenever I start Excel or uninstall/install this add-in, it errors out on
naming the commandbar. I get "Invalid procedure call or argument". It seems
to be naming the commandbar "Custom 1", and then it won't rename it. I'm
puzzled. thanks.

'===========================================
Sub Auto_Open()
Call CreateMenubar
End Sub

'===========================================
Sub Auto_Close()
Call RemoveMenubar
End Sub

'===========================================
Sub RemoveMenubar()
On Error Resume Next
Application.CommandBars("View").Delete
On Error GoTo 0
End Sub

'===========================================
Sub CreateMenubar()

Call RemoveMenubar

With Application.CommandBars.Add
.Name = "View" '<<<<<<<<<Errors here
.Left = 200
.Top = 200
.Protection = msoBarNoProtection
.Visible = True
.Position = msoBarFloating

With .Controls.Add(Type:=msoControlButton)
.OnAction = "'" & ThisWorkbook.Name & "'!" & "Unhide_All_WS"
.Caption = "Unhide All Sheets"
.Style = msoButtonIconAndCaption
.FaceId = 229
End With

End With
End Sub


JE McGimpsey

Creating toolbar macro errors
 
You need to choose a name that's not already being used by another
commandbar.

In article ,
Jason Morin wrote:

Hello. Below is some Dave Peterson code that I found (and modified). I simply
want to create a floating toolbar with one button for my macro. However,
whenever I start Excel or uninstall/install this add-in, it errors out on
naming the commandbar. I get "Invalid procedure call or argument". It seems
to be naming the commandbar "Custom 1", and then it won't rename it. I'm
puzzled. thanks.

'===========================================
Sub Auto_Open()
Call CreateMenubar
End Sub

'===========================================
Sub Auto_Close()
Call RemoveMenubar
End Sub

'===========================================
Sub RemoveMenubar()
On Error Resume Next
Application.CommandBars("View").Delete
On Error GoTo 0
End Sub

'===========================================
Sub CreateMenubar()

Call RemoveMenubar

With Application.CommandBars.Add
.Name = "View" '<<<<<<<<<Errors here
.Left = 200
.Top = 200
.Protection = msoBarNoProtection
.Visible = True
.Position = msoBarFloating

With .Controls.Add(Type:=msoControlButton)
.OnAction = "'" & ThisWorkbook.Name & "'!" & "Unhide_All_WS"
.Caption = "Unhide All Sheets"
.Style = msoButtonIconAndCaption
.FaceId = 229
End With

End With
End Sub


JE McGimpsey

Creating toolbar macro errors
 
Oops - should have been commandbar or menu bar popup.

In article ,
JE McGimpsey wrote:

You need to choose a name that's not already being used by another
commandbar.



All times are GMT +1. The time now is 09:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com