Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Call Macro using right click menu

Dear all,

I want to write a macro program so that when right click at on the
worksheet, an item is added to the right-click menu with the name of macro
function, so that the users can call the macro program by right clicking the
worksheet. On the other hand, other regular items such as "Copy",
"Paste",..,etc., should be preserved on the right-click menu.
Can anyone advise how to do this programatically? Thanks in advance!

Ivan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Call Macro using right click menu


Why not just add a command button with the macro assigned
----------------
Ben


--
protonLeah
------------------------------------------------------------------------
protonLeah's Profile: http://www.excelforum.com/member.php...o&userid=32097
View this thread: http://www.excelforum.com/showthread...hreadid=538298

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Call Macro using right click menu

One way:

Option Explicit
Sub auto_close()
Call CleanUpPly
End Sub
Sub auto_open()

Dim iCtr As Long
Dim myMacros As Variant
Dim myCaptions As Variant

Call CleanUpPly

Dim cb As CommandBar
Set cb = Application.CommandBars("ply")

myMacros = Array("mac1", "mac2", "mac3")
myCaptions = Array("Cap 1", "Cap 2", "Cap 3")

With cb.Controls
For iCtr = LBound(myMacros) To UBound(myMacros)
With .Add(Type:=msoControlButton, temporary:=True)
.Caption = myCaptions(iCtr)
.OnAction = "'" & ThisWorkbook.Name & "'!" & myMacros(iCtr)
.Tag = "__myPlyMacs__"
End With
Next iCtr
End With

End Sub
Sub CleanUpPly()
Dim ctrl As CommandBarControl

On Error Resume Next
Do
Set ctrl = Application.CommandBars("Ply") _
.FindControl(Tag:="__myPlyMacs__")
If ctrl Is Nothing Then
Err.Clear
Exit Do
End If
ctrl.Delete
Loop
On Error GoTo 0

End Sub

Ivan wrote:

Dear all,

I want to write a macro program so that when right click at on the
worksheet, an item is added to the right-click menu with the name of macro
function, so that the users can call the macro program by right clicking the
worksheet. On the other hand, other regular items such as "Copy",
"Paste",..,etc., should be preserved on the right-click menu.
Can anyone advise how to do this programatically? Thanks in advance!

Ivan


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Call Macro using right click menu

Thanks a lot Dave!

"Dave Peterson" wrote:

One way:

Option Explicit
Sub auto_close()
Call CleanUpPly
End Sub
Sub auto_open()

Dim iCtr As Long
Dim myMacros As Variant
Dim myCaptions As Variant

Call CleanUpPly

Dim cb As CommandBar
Set cb = Application.CommandBars("ply")

myMacros = Array("mac1", "mac2", "mac3")
myCaptions = Array("Cap 1", "Cap 2", "Cap 3")

With cb.Controls
For iCtr = LBound(myMacros) To UBound(myMacros)
With .Add(Type:=msoControlButton, temporary:=True)
.Caption = myCaptions(iCtr)
.OnAction = "'" & ThisWorkbook.Name & "'!" & myMacros(iCtr)
.Tag = "__myPlyMacs__"
End With
Next iCtr
End With

End Sub
Sub CleanUpPly()
Dim ctrl As CommandBarControl

On Error Resume Next
Do
Set ctrl = Application.CommandBars("Ply") _
.FindControl(Tag:="__myPlyMacs__")
If ctrl Is Nothing Then
Err.Clear
Exit Do
End If
ctrl.Delete
Loop
On Error GoTo 0

End Sub

Ivan wrote:

Dear all,

I want to write a macro program so that when right click at on the
worksheet, an item is added to the right-click menu with the name of macro
function, so that the users can call the macro program by right clicking the
worksheet. On the other hand, other regular items such as "Copy",
"Paste",..,etc., should be preserved on the right-click menu.
Can anyone advise how to do this programatically? Thanks in advance!

Ivan


--

Dave Peterson

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
Can I add a Macro to right-click Menu? Ed Excel Discussion (Misc queries) 8 October 11th 06 02:43 PM
How to call a sub defined in macro when double click a cell? Ivan Excel Programming 3 November 20th 05 09:46 PM
Assign macro to right click menu ? Richard[_35_] Excel Programming 1 August 25th 05 03:49 PM
Call Userfor and click button with macro ExcelMonkey[_190_] Excel Programming 2 February 25th 05 04:41 PM
Macro doesn't perform correctly when using right click menu David Cuthill[_2_] Excel Programming 2 July 26th 04 06:15 PM


All times are GMT +1. The time now is 04:52 PM.

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"