How do you get a macro to reference the worksheet it is being run
On Tue, 11 Aug 2009 01:57:02 -0700, Michelle D
wrote:
How do you get a macro to reference the worksheet it is being run from?
How do you write in the macro formula "take data from sheet macro is being
run from" (macro is being run from a submit button on a sheet - but I would
like to make a template and have lots of similiar sheets so I need it to
identify where it is being run from - not reference the template)
Since the button is going to be on the ActiveSheet, all you need to do
is use that as a reference. You can also store it as a variable if you
need to, like so:
Private Sub CommandButton1_Click()
Dim wks As Excel.Worksheet
Set wks = ActiveSheet
'Do other stuff
MsgBox wks.Name
Set wks = Nothing
End Sub
---------------------------------------------------------
Hank Scorpio
scorpionet who hates spam is {Between permanent e-mail addresses at this time, which makes the next line of my signature redundant}
* Please keep all replies in this Newsgroup. Thanks! *
|