Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel - calling macro from custom toolbar

Status
Not open for further replies.

cdipaolo

Programmer
May 1, 2002
36
US
I have a very simple macro in Excel that selects a sheet that is passed in - something like:

Sub GetSheet (strSheet As String)

Sheets(strSheet).Select

End Sub

This macro works running it by itself or if attaching to a command button. Now, when I create a custom menu and attach this macro to the .onAction of the menu item, it will not work. I have inserted a MsgBox command in the macro, so I know it's getting to it, but the other sheet is not being selected. Any ideas?
 
How are you passing the argument to the sub (this question goes for both the commandbutton and the menu item)?
Rob
[flowerface]
 
You need to do

.onaction = "DoGetSheet"


then define

sub DoGetSheet
GetSheet(your params here)
end sub

Sub GetSheet (strSheet As String)

Sheets(strSheet).Select

End Sub

 
Thanks to both of you - turned out to be something really simple. Forgetting about passing a sheet, it wasn't working hard coded. The reason is that I was calling

.onAction = "GotoSheet()" when I should have put
.onAction = "GotoSheet"

The post from aMember made me think about my syntax. Thanks again for the quick replies!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top