I have a dynamic rightclick menu, that I use to switch between the sheets, and select the necessary lines. My problem is that when the program starts run the macro with the ".onaction" method, the Worksheets("xy") does not prevail.
This is an example without any completeness:
[...]
Dim ws As Worksheet, i as long
i=0
For Each ws In ActiveWorkbook.Worksheets
Menu1.Controls.add (msoControlButton)
Menu1.Controls(i).Caption = ws.Name
Menu1.Controls(i).OnAction = "SheetChange(""" & ws.Name & """)"
i=i+1
Next
[...]
Sub SheetChange(x as string)
worksheets(x).activate
worksheets(x).Range("A1").select
end sub
Is there any way to use "activate" and "select" methods inside a sub, which called with ".onaction"?
ActiveWorkbook
the workbook you mean to work with, and does it change between the moment you setup your menu buttons and the moment you click them? – Mathieu Guindon.Caption = ws.Name
,.OnAction = "SheetChange(""" & ws.Name & """)"
. – Mathieu Guindon