Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Passing Variables between Workbooks

Does anyone know how to pass/call a global variable between two workbooks?
Both workbooks have a Global variable declared in module1 called wkName. Any
thoughts?

Set wbResults2 = ActiveWorkbook
Set wbResults1 = Workbooks.Open(StrName)
???
wbResults2.Close savechanges:=False
--
PK
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 897
Default Passing Variables between Workbooks

Hello,

You should set the workbook name to a variable, then you can use it as
you want.

Dim AWS as String
AWS = ActiveWorkbook.Name

Then you can do

Workbooks(AWS).Close
Windows(AWS).Activate


And so on.


HTH,
JP


On Dec 26, 2:18*pm, Patrick Kirk
wrote:
Does anyone know how to pass/call a global variable between two workbooks?
Both workbooks have a Global variable declared in module1 called wkName. Any
thoughts?

Set wbResults2 = ActiveWorkbook
Set wbResults1 = Workbooks.Open(StrName)
???
wbResults2.Close savechanges:=False
--
PK


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Passing Variables between Workbooks

JP, I tried and get the run-time error 438, object doesn't suipport this
property or method. Any thoughts?
--
PK


"JP" wrote:

Hello,

You should set the workbook name to a variable, then you can use it as
you want.

Dim AWS as String
AWS = ActiveWorkbook.Name

Then you can do

Workbooks(AWS).Close
Windows(AWS).Activate


And so on.


HTH,
JP


On Dec 26, 2:18 pm, Patrick Kirk
wrote:
Does anyone know how to pass/call a global variable between two workbooks?
Both workbooks have a Global variable declared in module1 called wkName. Any
thoughts?

Set wbResults2 = ActiveWorkbook
Set wbResults1 = Workbooks.Open(StrName)
???
wbResults2.Close savechanges:=False
--
PK



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Passing Variables between Workbooks

To link to the code of another book, you would need to make it a reference
(like for a library reference). This is not at all convenient.

You could use a Named Range or just a book Name to stored that variable.
Workbook Name
-------------------
' say Book1.xls
Workbooks("book1.xls").Names.Add "myvar","=""Hello"""
creates a name called 'myvar' and set it to the value 'Hello'
or for a number:
Workbooks("book1.xls").Names.Add "myvar","=3"
creates a name called 'myvar' and set it to the value 'Hello'

Now from another book, you can retrieve this value from a worksheet:
=book1!myvar
or through code
application.evaluate(aworkbooks("book1.xls").Names ("myvar").Value)

Named Range
----------------
Similar to above.

Book name vs. Named Range: not sure, but I would tend to say that the later
is accessible when the book is closed, whcih could be very convenient. But i
haven't tested.

--
Regards,
Sébastien
<http://www.ondemandanalysis.com
<http://www.ready-reports.com


"Patrick Kirk" wrote:

Does anyone know how to pass/call a global variable between two workbooks?
Both workbooks have a Global variable declared in module1 called wkName. Any
thoughts?

Set wbResults2 = ActiveWorkbook
Set wbResults1 = Workbooks.Open(StrName)
???
wbResults2.Close savechanges:=False
--
PK

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
Passing variables between workbooks mliungman Excel Programming 9 January 13th 06 02:22 PM
Passing Variables Jeff Excel Discussion (Misc queries) 1 November 4th 05 06:46 PM
Passing variables from one sub to another Yasha Avshalumov Excel Programming 4 August 19th 05 04:52 PM
Passing Variables Paula[_3_] Excel Programming 1 August 23rd 04 06:55 PM
Passing Variables Royce[_2_] Excel Programming 1 November 20th 03 02:16 PM


All times are GMT +1. The time now is 03:46 AM.

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

About Us

"It's about Microsoft Excel"