Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Custom Menus and OnAction

I have the following code.


Private Sub Workbook_Open()
' Add menu item for Finops.
With Application.CommandBars("WorkSheet Menu
Bar").Controls.Add(Type:=msoControlPopup)
.Caption = "MyMenu"

' Add menu items for showing and hiding groups of sheets.
With .Controls.Add(msoControlPopup, 1)
.BeginGroup = True
.Caption = "Options"

' Sub Menus.
With .Controls.Add(msoControlButton, 1)
.Caption = "Option1"
.Tag = 0
.OnAction = "modMain.DoSomeThing"
End With

With .Controls.Add(msoControlButton, 1)
.Caption = "Option2"
.Tag = 1
.OnAction = "modMain.DoSomeThing"
End With

End With

End With
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.CommandBars("WorkSheet Menu Bar").Controls("MyMenu").Delete
End Sub

When I select "Option1" or "Option2" from my custom menu and the Sub
DoSomeThing is executed. I need to know what sub menu called it/was clicked.
Both sub menus call the same Sub.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Custom Menus and OnAction

Sub DoSomeThing()

Select Case Application.CommandBars.ActionControl.Caption

Case "Option1"

'do option 1's thing

Case "Option2"

'do option 2's thing
End Select

End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Kent Prokopy" wrote in message
...
I have the following code.


Private Sub Workbook_Open()
' Add menu item for Finops.
With Application.CommandBars("WorkSheet Menu
Bar").Controls.Add(Type:=msoControlPopup)
.Caption = "MyMenu"

' Add menu items for showing and hiding groups of sheets.
With .Controls.Add(msoControlPopup, 1)
.BeginGroup = True
.Caption = "Options"

' Sub Menus.
With .Controls.Add(msoControlButton, 1)
.Caption = "Option1"
.Tag = 0
.OnAction = "modMain.DoSomeThing"
End With

With .Controls.Add(msoControlButton, 1)
.Caption = "Option2"
.Tag = 1
.OnAction = "modMain.DoSomeThing"
End With

End With

End With
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.CommandBars("WorkSheet Menu Bar").Controls("MyMenu").Delete
End Sub

When I select "Option1" or "Option2" from my custom menu and the Sub
DoSomeThing is executed. I need to know what sub menu called it/was
clicked.
Both sub menus call the same Sub.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 471
Default Custom Menus and OnAction

Why not just call 2 different subs that then in turn call the current sub you
are now calling. Then you would know which one called it because you'd have
that information before you call the sub. To do this you could use a public
variable that you set to either 1 or 2. Then in the subsequent sub that is
called the value would be either 1 or 2, depdning on which sub was called
before you get to the final sub. HTH

To declare a public variable, just go to the area above the first sub and
type:
Public WhichOneCalled as integer
These 3 subs would all be in your modmain module.

"Kent Prokopy" wrote:

I have the following code.


Private Sub Workbook_Open()
' Add menu item for Finops.
With Application.CommandBars("WorkSheet Menu
Bar").Controls.Add(Type:=msoControlPopup)
.Caption = "MyMenu"

' Add menu items for showing and hiding groups of sheets.
With .Controls.Add(msoControlPopup, 1)
.BeginGroup = True
.Caption = "Options"

' Sub Menus.
With .Controls.Add(msoControlButton, 1)
.Caption = "Option1"
.Tag = 0
.OnAction = "modMain.DoSomeThing"
End With

With .Controls.Add(msoControlButton, 1)
.Caption = "Option2"
.Tag = 1
.OnAction = "modMain.DoSomeThing"
End With

End With

End With
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.CommandBars("WorkSheet Menu Bar").Controls("MyMenu").Delete
End Sub

When I select "Option1" or "Option2" from my custom menu and the Sub
DoSomeThing is executed. I need to know what sub menu called it/was clicked.
Both sub menus call the same Sub.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Custom Menus and OnAction

I could not find this online anywhere.
Application.CommandBars.ActionControl.Caption

YOU ARE MY HERO...

Thank you

"Bob Phillips" wrote:

Sub DoSomeThing()

Select Case Application.CommandBars.ActionControl.Caption

Case "Option1"

'do option 1's thing

Case "Option2"

'do option 2's thing
End Select

End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Kent Prokopy" wrote in message
...
I have the following code.


Private Sub Workbook_Open()
' Add menu item for Finops.
With Application.CommandBars("WorkSheet Menu
Bar").Controls.Add(Type:=msoControlPopup)
.Caption = "MyMenu"

' Add menu items for showing and hiding groups of sheets.
With .Controls.Add(msoControlPopup, 1)
.BeginGroup = True
.Caption = "Options"

' Sub Menus.
With .Controls.Add(msoControlButton, 1)
.Caption = "Option1"
.Tag = 0
.OnAction = "modMain.DoSomeThing"
End With

With .Controls.Add(msoControlButton, 1)
.Caption = "Option2"
.Tag = 1
.OnAction = "modMain.DoSomeThing"
End With

End With

End With
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.CommandBars("WorkSheet Menu Bar").Controls("MyMenu").Delete
End Sub

When I select "Option1" or "Option2" from my custom menu and the Sub
DoSomeThing is executed. I need to know what sub menu called it/was
clicked.
Both sub menus call the same Sub.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Custom Menus and OnAction

ActionControl refers to the selected button, so it gives you access to all
of its properties, as well as Caption.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Kent Prokopy" wrote in message
...
I could not find this online anywhere.
Application.CommandBars.ActionControl.Caption

YOU ARE MY HERO...

Thank you

"Bob Phillips" wrote:

Sub DoSomeThing()

Select Case Application.CommandBars.ActionControl.Caption

Case "Option1"

'do option 1's thing

Case "Option2"

'do option 2's thing
End Select

End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

"Kent Prokopy" wrote in message
...
I have the following code.


Private Sub Workbook_Open()
' Add menu item for Finops.
With Application.CommandBars("WorkSheet Menu
Bar").Controls.Add(Type:=msoControlPopup)
.Caption = "MyMenu"

' Add menu items for showing and hiding groups of sheets.
With .Controls.Add(msoControlPopup, 1)
.BeginGroup = True
.Caption = "Options"

' Sub Menus.
With .Controls.Add(msoControlButton, 1)
.Caption = "Option1"
.Tag = 0
.OnAction = "modMain.DoSomeThing"
End With

With .Controls.Add(msoControlButton, 1)
.Caption = "Option2"
.Tag = 1
.OnAction = "modMain.DoSomeThing"
End With

End With

End With
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.CommandBars("WorkSheet Menu
Bar").Controls("MyMenu").Delete
End Sub

When I select "Option1" or "Option2" from my custom menu and the Sub
DoSomeThing is executed. I need to know what sub menu called it/was
clicked.
Both sub menus call the same 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
Custom menus don't appear under custom ribbon tab Misbah Excel Programming 2 April 15th 08 01:29 AM
Custom FaceID's for Custom Menus triaz[_4_] Excel Programming 2 March 1st 06 10:34 AM
Custom faces for custom menus/commandbars Stu Valentine Excel Programming 1 September 17th 04 04:28 AM
VBE Custom menuitem not calling OnAction macro R Avery Excel Programming 4 July 13th 04 10:39 PM
Setting OnAction of custom menu item? Ed[_18_] Excel Programming 12 May 10th 04 02:55 PM


All times are GMT +1. The time now is 11:36 PM.

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

About Us

"It's about Microsoft Excel"