francoisferreira
New Member
- Joined
- Jul 21, 2005
- Messages
- 24
Hi, does anybody know how I can refer to a public constant in a different workbook's (which is already open) VBA from the workbook which I am currently working on's VBA?
MsgBox PROJECT1.MyValue
You can also use a public property in the ThisWorkbook module of the other workbook to return the constant value. Then you don't need a reference.
Const MYCONSTANT = 100
Property Get ConstantValue()
ConstantValue = MYCONSTANT
End Property
Sub GetVal()
MsgBox Workbooks("OtherWorkbook").ConstantValue
End Sub
Private Const MyConstant As Integer = 10
Public Property Get GetConstant() As Integer
GetConstant = MyConstant
End Property
Sub Example()
'read property from Book1.xls
MsgBox Workbooks("Book1.xls").GetConstant
End Sub