Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 2
Default Macro - onAction arguments

Hello.
I have this code:

Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Application.CommandBars("Cell").Reset
For Each Worksheet In Application.Worksheets
With Application.CommandBars("Cell").Controls
With .Add
.Caption = Worksheet.Name
.OnAction = "someMacro"
.Tag = "someTag"
.BeginGroup = True
End With
End With
Next
End Sub

It adds all sheets in the context menu.
There is just one more thing to be done.
When you click on a sheet from the context menu, it must became active.
Something like .OnAction = Worksheet.Select or a separate macro ....
I am not sure how to do it so i need some advice.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Macro - onAction arguments

Excel keeps track of what control you click on and you can use that:

Option Explicit
Sub SomeMacro()
MsgBox Application.CommandBars.ActionControl.Caption
thisworkbook.worksheets(Application.CommandBars.Ac tionControl.Caption) _
.select
End Sub

But...
It's not a good idea to use a variable that shares a name with a VBA keyword
(like Worksheet).

Option Explicit
Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, _
ByVal Target As Range, Cancel As Boolean)

Dim wks As Worksheet

'this is usually a bad idea!
'You just reset the user's rightclick menu popup!
Application.CommandBars("Cell").Reset

For Each wks In Me.Worksheets
With Application.CommandBars("Cell").Controls
With .Add
.Caption = wks.Name
.OnAction = "'" & Me.Name & "'!someMacro"
.Tag = "someTag"
.BeginGroup = True 'between each name????
End With
End With
Next wks
End Sub

And another but...

I wouldn't want you to reset my popup toolbar. I have a personal.xla (or .xls)
that I use to modify my toolbars -- including the Cell popup.

Instead, you may want to look at this alternative from Debra Dalgleish's site:
http://contextures.com/xlToolbar01.html
And she points to an xl2007 version by Ron de Bruin:
http://contextures.com/xlToolbar01b.html



version83 wrote:

Hello.
I have this code:

Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal
Target As Range, Cancel As Boolean)
Application.CommandBars("Cell").Reset
For Each Worksheet In Application.Worksheets
With Application.CommandBars("Cell").Controls
With .Add
Caption = Worksheet.Name
OnAction = "someMacro"
Tag = "someTag"
BeginGroup = True
End With
End With
Next
End Sub

It adds all sheets in the context menu.
There is just one more thing to be done.
When you click on a sheet from the context menu, it must became
active.
Something like .OnAction = Worksheet.Select or a separate macro ....
I am not sure how to do it so i need some advice.

--
version83


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Macro - onAction arguments

This macro has a bug in it.

Option Explicit
Sub SomeMacro()
MsgBox Application.CommandBars.ActionControl.Caption
thisworkbook.worksheets(Application.CommandBars.Ac tionControl.Caption) _
.select
End Sub

It'll only appear when the workbook with the code isn't the activeworkbook.

Try:

Option Explicit
Sub SomeMacro()
MsgBox Application.CommandBars.ActionControl.Caption
thisworkbook.activate '<-- added
thisworkbook.worksheets(Application.CommandBars.Ac tionControl.Caption) _
.select
End Sub

(but I still don't like messing up that Cell popup menu!)

Dave Peterson wrote:

Excel keeps track of what control you click on and you can use that:

Option Explicit
Sub SomeMacro()
MsgBox Application.CommandBars.ActionControl.Caption
thisworkbook.worksheets(Application.CommandBars.Ac tionControl.Caption) _
.select
End Sub

But...
It's not a good idea to use a variable that shares a name with a VBA keyword
(like Worksheet).

Option Explicit
Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, _
ByVal Target As Range, Cancel As Boolean)

Dim wks As Worksheet

'this is usually a bad idea!
'You just reset the user's rightclick menu popup!
Application.CommandBars("Cell").Reset

For Each wks In Me.Worksheets
With Application.CommandBars("Cell").Controls
With .Add
.Caption = wks.Name
.OnAction = "'" & Me.Name & "'!someMacro"
.Tag = "someTag"
.BeginGroup = True 'between each name????
End With
End With
Next wks
End Sub

And another but...

I wouldn't want you to reset my popup toolbar. I have a personal.xla (or .xls)
that I use to modify my toolbars -- including the Cell popup.

Instead, you may want to look at this alternative from Debra Dalgleish's site:
http://contextures.com/xlToolbar01.html
And she points to an xl2007 version by Ron de Bruin:
http://contextures.com/xlToolbar01b.html

version83 wrote:

Hello.
I have this code:

Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal
Target As Range, Cancel As Boolean)
Application.CommandBars("Cell").Reset
For Each Worksheet In Application.Worksheets
With Application.CommandBars("Cell").Controls
With .Add
Caption = Worksheet.Name
OnAction = "someMacro"
Tag = "someTag"
BeginGroup = True
End With
End With
Next
End Sub

It adds all sheets in the context menu.
There is just one more thing to be done.
When you click on a sheet from the context menu, it must became
active.
Something like .OnAction = Worksheet.Select or a separate macro ....
I am not sure how to do it so i need some advice.

--
version83


--

Dave Peterson


--

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
Passing several parameters to OnAction property. LABKHAND Excel Discussion (Misc queries) 1 April 24th 09 08:02 PM
OnAction of Menu Bar with variable parameters chris Excel Discussion (Misc queries) 1 August 7th 06 04:03 PM
Timing problem with OnAction! Fred Russell Charts and Charting in Excel 3 October 18th 05 06:11 PM
passing arguments from an excel macro to a word macro KWE39 Excel Discussion (Misc queries) 1 July 7th 05 03:56 PM
.ONACTION macro call fails Wayne Excel Discussion (Misc queries) 2 March 2nd 05 05:10 PM


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