ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Refer to Public Variable from Another Workbook (https://www.excelbanter.com/excel-programming/402591-refer-public-variable-another-workbook.html)

Mike H.

Refer to Public Variable from Another Workbook
 
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?`

Mike H.

Refer to Public Variable from Another Workbook
 
Figured it out:

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


"Mike H." wrote:

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?`


Susan

Refer to Public Variable from Another Workbook
 
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



On Dec 11, 2:41 pm, Mike H. wrote:
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?`



Susan

Refer to Public Variable from Another Workbook
 
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


On Dec 11, 3:22 pm, Mike H. wrote:
Figured it out:

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



"Mike H." wrote:
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?`- Hide quoted text -


- Show quoted text -




All times are GMT +1. The time now is 12:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com