Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 312
Default Use variable across workbooks

Hello. I have a workbook with a click event. The click event opens another
workbook and runs a procedure in the newly opened workbook.

I would like to read the contents of of Sheet1, cell A1 in the file that
houses the click event, and be able to use that variable in the code in the
workbook that the click event opened. Can this be done?? Thanks.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default Use variable across workbooks

Yes you can; you'll get the idea from this:

workbooks("Book1").Sheets("Sheet1").Range("A2").va lue
=workbooks("Book2").Sheets("Sheet1").Range("A1").v alue
or
myVar=workbooks("Book1").Sheets("Sheet1").Range("A 2").value
or
MyFunction(workbooks("Book1").Sheets("Sheet1").Ran ge("A2").value )

This may not be robust as it assumes the names of the workbooks and sheets
etc etc.
What you cannot do so easily is cross-reference a variable in the VBA code
of one workbook in another.

"Steph" wrote:

Hello. I have a workbook with a click event. The click event opens another
workbook and runs a procedure in the newly opened workbook.

I would like to read the contents of of Sheet1, cell A1 in the file that
houses the click event, and be able to use that variable in the code in the
workbook that the click event opened. Can this be done?? Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 312
Default Use variable across workbooks

That's part of the problem - I won't know the name of the file or sheet name
of the workbook that houses the click event whic then opens and runs the
code in the newly opened workbook. So somehow I need the contents of cell
A1 to carry over and be available to me in the newly oppened workbook.

"AA2e72E" wrote in message
...
Yes you can; you'll get the idea from this:

workbooks("Book1").Sheets("Sheet1").Range("A2").va lue
=workbooks("Book2").Sheets("Sheet1").Range("A1").v alue
or
myVar=workbooks("Book1").Sheets("Sheet1").Range("A 2").value
or
MyFunction(workbooks("Book1").Sheets("Sheet1").Ran ge("A2").value )

This may not be robust as it assumes the names of the workbooks and sheets
etc etc.
What you cannot do so easily is cross-reference a variable in the VBA code
of one workbook in another.

"Steph" wrote:

Hello. I have a workbook with a click event. The click event opens

another
workbook and runs a procedure in the newly opened workbook.

I would like to read the contents of of Sheet1, cell A1 in the file that
houses the click event, and be able to use that variable in the code in

the
workbook that the click event opened. Can this be done?? Thanks.





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
retrieving data from variable workbooks lutan Excel Discussion (Misc queries) 3 August 14th 07 01:08 PM
Variable Link to Workbooks dfrancefort Excel Worksheet Functions 1 April 28th 05 01:15 AM
Passing a variable between workbooks Rich Cooper Excel Programming 1 May 19th 04 07:27 PM
Sharing variable values between open workbooks? Julian Milano[_2_] Excel Programming 0 January 29th 04 01:13 AM
How to refer a Variable across Workbooks ? Prabhu Dev Excel Programming 1 November 27th 03 05:22 AM


All times are GMT +1. The time now is 09:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"