LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 363
Default Variable workbook name references

These suggestions would work if I explicitly knew the name of the destination
file, but I only have it as a constructed string that changes a number of
times in the macro. I'm probably doing something wrong, but I'm not sure
where.
Let give a better example of what I'm trying to do.

Private sub workbook_open()
dim mypath as range
dim var1 as string
dim var2 as string
dim myWb as workbook
var1 =workbooks("Master.xls").sheets(1).range("A1")
var2=workbooks("Master.xls").sheets(1).range("B1")
mypath=var1 & var2 & "\Summary.xls" ' This is a valid path name of a file
that is already open.
set myWb =workbooks(mypath) ' But this doesn't work

' I have a loop with my desired copy statement and variables
' to change source and destination, including myWb as needed.
'
cells(m,n).copy destination:=myWb.sheets("xxx").range("yyy")
'
end sub
--
Al C


"JLGWhiz" wrote:

If you set your variable:
Set destWkb = Workbooks("Wkbk1.xls").Sheets(ShName)

Then:
ActiveWorkbook.Cells(1, 1).Copy destWkb.Range("A1")

Should give the same result as:

Cells(1,1).Copy
Destination:=Workbooks(€śWkbk1.xls€ť).Sheets(€ś Name€ť).Range("A1")


"Al" wrote:

If I read your example correctly, the active workbook is the destination,
whereas I have the opposite case. I could do this if I knew how to declare
the inactive workbooks as objects, since I can synthesize their names. What
I want to do is:

Set MyBook = SynthesizedWorkbook
--
Al C


"JP" wrote:

A variable which refers to a workbook has to be declared as a Workbook
object, ex:

Dim MyBook As Excel.Workbook
Set MyBook = ActiveWorkbook

Then you can use "MyBook" in place of the workbook reference, i.e.

Workbooks("My Old Workbook").Cells(1,1).Copy MyBook.Sheets("My
Sheet").Range("A1")


Is that what you needed?

--JP

On Apr 14, 3:01 pm, Al wrote:
I want to copy values from my active workbook to a series of open, inactive
workbooks. I know this can be done by explicitly naming each destination
workbook:

Cells(1,1).Copy
Destination:=Workbooks("Wkbk1.xls").Sheets("Name") .Range("A1")

In my application, I want to synthesize the workbook names as variables from
values in a master file and replace the workbook name "Wkbk.xls" with each
variable needed. If I try to just replace the name with a variable, I get a
"Subscript out of range" error. How can I do this without having to activate
each workbook in turn?

--
Al C


 
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
variable cell references jjk98 Excel Discussion (Misc queries) 4 April 30th 08 01:38 AM
VLOOKUP variable array references Simon Excel Discussion (Misc queries) 1 June 22nd 07 07:09 PM
variable cell references ???? kiethb Excel Discussion (Misc queries) 2 February 10th 06 08:22 PM
Variable Column references Gidders Excel Worksheet Functions 1 July 15th 05 07:54 PM
variable worksheet references mattbloodgood Excel Discussion (Misc queries) 3 July 7th 05 08:34 PM


All times are GMT +1. The time now is 12:54 PM.

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"