Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Adding events to newly add Menu

hi

All
I am adding a new menus in excel. these menus are
generated dynamically. there is no fix number of menus. I
am generating it using loop.

now i want to assign a click event to every menuitem, in
termes of VBA for every office.CommandBarButton

I have declared one object of this type with withevent
keyword.
the problem is how do I assign these many menusitems to
this withevent object.

It is not possible to create that many withevents object
dynamically for each menuitem.

please send your answers
waiting for reply
regards
Amod
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Adding events to newly add Menu

Amod,

This is a good time to use a class module. Create a class module called
CCmdControl and insert the following code:

Public WithEvents CmdButton As Office.CommandBarButton
Private Sub CmdButton_Click(ByVal Ctrl As Office.CommandBarButton, _
CancelDefault As Boolean)
MsgBox "You clicked: " & Ctrl.Caption
End Sub

Then, in a standard code module, insert the following code:

Public Coll As New Collection

Sub CreateMenu()
Dim CtrlObj As CCmdControl
Dim Ctrl As Office.CommandBarButton
' create the command bar button here
Set Ctrl = Application.CommandBars("Worksheet Menu
Bar").Controls("Tools").Controls.Add(temporary:=Tr ue)
With Ctrl
.Caption = "Click Me"
.Visible = True
' set other properties
End With
Set CtrlObj = New CCmdControl
Set CtrlObj.CmdButton = Ctrl
Coll.Add CtrlObj

Set Ctrl = Application.CommandBars("Worksheet Menu
Bar").Controls("Tools").Controls.Add(temporary:=Tr ue)
With Ctrl
.Caption = "Click Me2"
.Visible = True
' set other properties
End With
Set CtrlObj = New CCmdControl
Set CtrlObj.CmdButton = Ctrl
Coll.Add CtrlObj
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"Amod" wrote in message
...
hi

All
I am adding a new menus in excel. these menus are
generated dynamically. there is no fix number of menus. I
am generating it using loop.

now i want to assign a click event to every menuitem, in
termes of VBA for every office.CommandBarButton

I have declared one object of this type with withevent
keyword.
the problem is how do I assign these many menusitems to
this withevent object.

It is not possible to create that many withevents object
dynamically for each menuitem.

please send your answers
waiting for reply
regards
Amod



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Adding events to newly add Menu


Hello sir
Thanks for your precious help.
regards
Amod
-----Original Message-----
Amod,

This is a good time to use a class module. Create a

class module called
CCmdControl and insert the following code:

Public WithEvents CmdButton As Office.CommandBarButton
Private Sub CmdButton_Click(ByVal Ctrl As

Office.CommandBarButton, _
CancelDefault As Boolean)
MsgBox "You clicked: " & Ctrl.Caption
End Sub

Then, in a standard code module, insert the following

code:

Public Coll As New Collection

Sub CreateMenu()
Dim CtrlObj As CCmdControl
Dim Ctrl As Office.CommandBarButton
' create the command bar button here
Set Ctrl = Application.CommandBars("Worksheet Menu
Bar").Controls("Tools").Controls.Add(temporary:=T rue)
With Ctrl
.Caption = "Click Me"
.Visible = True
' set other properties
End With
Set CtrlObj = New CCmdControl
Set CtrlObj.CmdButton = Ctrl
Coll.Add CtrlObj

Set Ctrl = Application.CommandBars("Worksheet Menu
Bar").Controls("Tools").Controls.Add(temporary:=T rue)
With Ctrl
.Caption = "Click Me2"
.Visible = True
' set other properties
End With
Set CtrlObj = New CCmdControl
Set CtrlObj.CmdButton = Ctrl
Coll.Add CtrlObj
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"Amod" wrote in

message
...
hi

All
I am adding a new menus in excel. these menus are
generated dynamically. there is no fix number of menus.

I
am generating it using loop.

now i want to assign a click event to every menuitem, in
termes of VBA for every office.CommandBarButton

I have declared one object of this type with withevent
keyword.
the problem is how do I assign these many menusitems to
this withevent object.

It is not possible to create that many withevents object
dynamically for each menuitem.

please send your answers
waiting for reply
regards
Amod



.

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
Adding dates to events Wally3178 Excel Discussion (Misc queries) 1 April 15th 08 08:54 AM
Adding buttons to a new menu bar Greegan Excel Worksheet Functions 1 April 7th 06 07:55 AM
Adding a menu DMc2005 Excel Discussion (Misc queries) 3 October 2nd 05 04:14 PM
Add list to newly created menu Anthony Excel Discussion (Misc queries) 4 February 25th 05 01:53 AM
add list to newly created menu Anthony Excel Worksheet Functions 1 February 25th 05 12:57 AM


All times are GMT +1. The time now is 10:43 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"