Refer to Public Variable from Another Workbook

M

Mike H.

I am workbook Other.xls, running a macro in module2. I wish to refer to a
public variable in wb1.xls, module1 called pubvar. I am doing things in the
wb1.xls file with the macro and need to set the value of a public variable
there so I can turn off some error checking that the file is performing. How
is this done?`
 
M

Mike H.

Figured it out:

Windows("wb1.xls").Activate
With Selection
Processingon = 1
End With
 
S

Susan

unless you're running the code in wb1.xls, module1, and have already
set the value of the variable within the code, and then the macro in
wb1.xls calls a macro in other.xls module2, you can't do it. because
the variable is only set during the time the macro is running - it's
not a tangible constant. if you want to use it that way, it'll have
to be a physical entry in a cell in wb1.xls (could be hidden) that can
be checked. when you run the macro in wb1.xls it could enter the
variable into that cell. the cell would stay constant until the macro
is run again.
hth
susan
 
S

Susan

what you are explaining as a solution doesn't seem to be what you
asked. here you're setting the variable, not reading it. but the
variable is located in other.xls, not wb1.xls.

i guess i misunderstood what you wanted. you can only set a variable
inside the macro that is running. but you probably already knew that.
:)
susan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top