Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Error when creating menu item on command bar

Below is my code. It worked fine until today and I didn't change
anything. I currently have this code in an .xla add-in, but the menu
that should be appearing on the Worksheet Menu Bar does not work. When
I try to run the code manually, I get the error

Method 'OnAction' of object '_CommandBarButton' failed

on the .Controls(MenuName).OnAction = "Conversion" line

Thanks for any help.

Sub Auto_Open()

Dim cWmb As String, cMm As String
Dim MenuName As String

cWmb = "Worksheet Menu Bar"
cMm = "Utilities"

Application.ScreenUpdating = False

'To delete any existing Utilities menus
On Error Resume Next
CommandBars(cWmb).Controls(cMm).Delete
On Error GoTo 0

'Add menu
CommandBars(cWmb).Controls.Add(Type:=msoControlPop up,
Befo=CommandBars(cWmb).Controls.Count - 1).Caption = cMm

'Use the menu to create the menu item(s)
With CommandBars(cWmb).Controls(cMm)
MenuName = "&Conversion"
.Controls.Add(Type:=msoControlButton).Caption = MenuName
.Controls(MenuName).OnAction = "Conversion"
End With
Application.ScreenUpdating = True

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 129
Default Error when creating menu item on command bar

When run from and xla file, I get a 'Invalid Procedure Call or
Function' error on line

CommandBars(cWmb).Controls.Add(Type:=msoControlPop up, _
Befo=CommandBars(cWmb).Controls.Count - 1).Caption = cMm

It runs fine when run from an .xls file. If you need this routine on
every new workbook, can you run it from an xlt file in your xlstart
directory?


Michael Malinsky wrote:
Below is my code. It worked fine until today and I didn't change
anything. I currently have this code in an .xla add-in, but the menu
that should be appearing on the Worksheet Menu Bar does not work. When
I try to run the code manually, I get the error

Method 'OnAction' of object '_CommandBarButton' failed

on the .Controls(MenuName).OnAction = "Conversion" line

Thanks for any help.

Sub Auto_Open()

Dim cWmb As String, cMm As String
Dim MenuName As String

cWmb = "Worksheet Menu Bar"
cMm = "Utilities"

Application.ScreenUpdating = False

'To delete any existing Utilities menus
On Error Resume Next
CommandBars(cWmb).Controls(cMm).Delete
On Error GoTo 0

'Add menu
CommandBars(cWmb).Controls.Add(Type:=msoControlPop up,
Befo=CommandBars(cWmb).Controls.Count - 1).Caption = cMm

'Use the menu to create the menu item(s)
With CommandBars(cWmb).Controls(cMm)
MenuName = "&Conversion"
.Controls.Add(Type:=msoControlButton).Caption = MenuName
.Controls(MenuName).OnAction = "Conversion"
End With
Application.ScreenUpdating = True

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Error when creating menu item on command bar

I'm not sure what happened, but it works now.

Thanks.

wrote:
When run from and xla file, I get a 'Invalid Procedure Call or
Function' error on line

CommandBars(cWmb).Controls.Add(Type:=msoControlPop up, _
Befo=CommandBars(cWmb).Controls.Count - 1).Caption = cMm

It runs fine when run from an .xls file. If you need this routine on
every new workbook, can you run it from an xlt file in your xlstart
directory?


Michael Malinsky wrote:
Below is my code. It worked fine until today and I didn't change
anything. I currently have this code in an .xla add-in, but the menu
that should be appearing on the Worksheet Menu Bar does not work. When
I try to run the code manually, I get the error

Method 'OnAction' of object '_CommandBarButton' failed

on the .Controls(MenuName).OnAction = "Conversion" line

Thanks for any help.

Sub Auto_Open()

Dim cWmb As String, cMm As String
Dim MenuName As String

cWmb = "Worksheet Menu Bar"
cMm = "Utilities"

Application.ScreenUpdating = False

'To delete any existing Utilities menus
On Error Resume Next
CommandBars(cWmb).Controls(cMm).Delete
On Error GoTo 0

'Add menu
CommandBars(cWmb).Controls.Add(Type:=msoControlPop up,
Befo=CommandBars(cWmb).Controls.Count - 1).Caption = cMm

'Use the menu to create the menu item(s)
With CommandBars(cWmb).Controls(cMm)
MenuName = "&Conversion"
.Controls.Add(Type:=msoControlButton).Caption = MenuName
.Controls(MenuName).OnAction = "Conversion"
End With
Application.ScreenUpdating = True

End Sub


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
creating my own menu item in excel [email protected] Excel Discussion (Misc queries) 1 March 16th 09 04:09 AM
Creating sub menu in Command bar Troispieds Excel Programming 5 June 20th 07 05:23 PM
Creating sub menu in Command bar micklloyd Excel Programming 2 January 26th 06 04:47 AM
Menu items added with menu item editor in older versions Michael Hoffmann Excel Discussion (Misc queries) 2 January 7th 05 01:40 PM
Adding a menu item right click menu when clicking on a single. Andoni[_28_] Excel Programming 0 September 2nd 04 10:23 PM


All times are GMT +1. The time now is 03:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"