worksheet name store in a variable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi guys,
I'm finishing up a macro and need to store the name of the macro in a
variable.

I want the macro to find out what worksheet the user is on, execute the
program which in this case is a webquery (which runs on a specific
worksheet), and return to the worksheet that the user was originally looking
at.

I'm thinking that the best way to do this is to first set a variable to the
name of the active worksheet, execute the program, and lastly to activate the
original worksheet by using the variable that was set in the first operation.

What do you guy think?
 
I'm sorry... I need the name of the active WORKSHEET to be stored in a
variable... not the name of the macro. Its late and I've been coding all
day...lol.
 
Hi Steve,

Rather than getting the name of the worksheet you can store a reference to
the the sheet as in

Dim s As Object

Set s = ActiveSheet
MsgBox "do other stuff", vbOKOnly
s.Activate

Thats it done.

Notice I used an object because you are not sure if it is a worksheet or a
chart that will be active when the macro is run if you are sure that it will
only be a worksheet then:

Dim s As worksheet

Set s = ActiveSheet
MsgBox "do other stuff", vbOKOnly
s.Activate

is prefered.
 
Back
Top