View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Variables Between Workbooks

You would need a function in workbookA that would return the value of that
variable

In a general module in WorkbookA.xls
' in the declarations section
Public lngVar as Long

' in the code section
Sub SetVar()
' or some code to set the value of the public variable
lngVar = int(rnd()*1000+1)
End Sub

Public Function MyVariable()
MyVariable = lngVar
End Function

then in the other workbooks you can do

lngA = Application.Run("WorkbookA.xls!MyVariable")

--
Regards,
Tom Ogilvy

wrote in message
ups.com...
Greetings,

I have a variable in one workbook that I want any other open workbook
to recognize. For example, workbook A declares variable X. I want
workbook B to also recognize variable X from workbook A.

I am a VBA novice, so please use layman's terms with your reply.

Many thanks,
David