Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default VBA Stmt Format to Get Contents of Cell in Another Book

I have two workbooks "A" & "B". I want a macro in
WorkbookA to fetch the contents of a named variable
("TestVal")in WorkbookB. For the life of me, I can't
remember how to format the statement. It will look
something like this:
Dim X as Integer
X = Workbooks("'C:\FolderNm\WorkbookB.xls'"!TestVal
which, of course, is incorrect. It seems I need a range
statement in there somewhere. I really would like to do
this without explicitly opening WorkbookB. I have set up
WorkbookB as a reference in WorkbookA's reference list, if
that's any help. Any suggestions?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default VBA Stmt Format to Get Contents of Cell in Another Book

Hi,

AFAIK you can't use VBA to read a closed workbook. But assuming the
workbook is open, the following should work.

Sub B()
Dim r As Range
Dim WB As Workbook
Set WB = Workbooks("WorkbookB.xls")
Set r = WB.Names("TestVal").RefersToRange
Debug.Print r.Value
End Sub

HTH

Peter Beach

"SidBord" wrote in message
...
I have two workbooks "A" & "B". I want a macro in
WorkbookA to fetch the contents of a named variable
("TestVal")in WorkbookB. For the life of me, I can't
remember how to format the statement. It will look
something like this:
Dim X as Integer
X = Workbooks("'C:\FolderNm\WorkbookB.xls'"!TestVal
which, of course, is incorrect. It seems I need a range
statement in there somewhere. I really would like to do
this without explicitly opening WorkbookB. I have set up
WorkbookB as a reference in WorkbookA's reference list, if
that's any help. Any suggestions?



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
Link format along with contents of another cell Claudia Excel Worksheet Functions 1 April 8th 09 07:24 PM
Format Cell contents as MM Sandy Excel Worksheet Functions 4 August 25th 08 05:16 PM
Can I format a row based on the contents of one cell? Kirsty Excel Discussion (Misc queries) 1 May 23rd 06 02:57 PM
If stmt and assigning a value to another cell lovethepirk Excel Worksheet Functions 3 April 13th 06 01:50 AM
Copying format to a new cell, w/o overwriting destination cell contents James C Excel Discussion (Misc queries) 1 October 18th 05 08:02 PM


All times are GMT +1. The time now is 09:00 AM.

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"