Add/Run Macro Through "Excel Popup Menu"

syed_mushraf

Active Member
Joined
Oct 13, 2002
Messages
261
Dear all,
How can recorded macros add as a popup menu bar to display every time in the menu and to run whenever they requried.
(Musahrraf)
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi,

You will need to store your macros in your Personal.xls workbook to have them available to all other workbooks. (If you don't already have one, record a macro and choose Personal.xls as the destination for saving the macro).

Then you will need to create a menu for your chosen macros. To be available every time you use Excel the menu should be created in the Workbook_Open event of the Personal.xls. Eg.<pre>Private Sub Workbook_Open()
Create_Menu.CreatePopup ' Menu item
End Sub</pre>
Then in a normal module (called Create_Menu in this example), in Personal.xls, add a menu creation routine. Eg.<pre>Sub CreatePopup()
Dim cbpop As CommandBarControl
Dim cbctl As CommandBarControl
Dim cbsub As CommandBarControl

For Each cbpop In Application.CommandBars _
("Worksheet Menu Bar").Controls
If cbpop.Caption = "&My Macros" Then End
Next

Set cbpop = Application.CommandBars("Worksheet Menu Bar"). _
Controls.Add(msoControlPopup, , , , False)
cbpop.Caption = "&My Macros"
cbpop.Visible = True

' add a menu item
Set cbctl = cbpop.Controls.Add(Type:=msoControlButton)
cbctl.Visible = True
cbctl.Style = msoButtonCaption 'required for caption
cbctl.Caption = "My first macro"
cbctl.OnAction = "FirstMacro" 'action to perform

End Sub

Sub RemovePopup()
Dim cbpop As CommandBarControl

' Removes Custom menu if temporary not set
For Each cbpop In Application.CommandBars _
("Worksheet Menu Bar").Controls
If cbpop.Caption = "&My Macros" Then cbpop.Delete
Next

End Sub</pre>

The second routine is to delete your custom menu if you wish to.

HTH

EDIT: Oops - typos!
_________________<font color="blue"> «««<font color="red">¤<font color="blue"><font size=+1>Richie</font><font color="red">¤<font color="blue"> »»»</font>

caffeine_sample.gif
</gif>
This message was edited by Richie(UK) on 2002-10-20 13:35
 
Upvote 0

Forum statistics

Threads
1,213,549
Messages
6,114,264
Members
448,558
Latest member
aivin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top