Variable workbook name references
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
|