Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Activating Workbook
HI,
When I start a macro that will work with two or more workbooks, I always have: Dim ThisBook as Workbook Set ThisBook=ActiveWorkbook When I open a second workbook for data: Dim DataBook as Workbook Set DataBook=ActiveWorkbook Now I simply use the workbook variables to qualify which range form which workbook to use. -- Rod Gill Project MVP NEW!! Project VBA Book, for details visit: http://www.projectvbabook.com "Jason" wrote in message ... I am trying to use some code to copy and paste a variety of cells from a master workbook ("WB1", which contains the code) to a second WB ("WB2"). The name of WB1 is fixed and will not change. However, WB2 will not always have the same filename. I would generally only be doing this one workbook at a time, i.e. I will have WB1 open along with WB2, and then run the code. Is there a way using code to reference/activate WB2 while I am in WB1 without having to use the filename of WB2 (it will not always be the same)? Thanks. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Activating Workbook
Instead of using your own variable ThisBook, you could use VBA's ThisWorkbook.
It'll refer to the workbook with the code. Rod Gill wrote: HI, When I start a macro that will work with two or more workbooks, I always have: Dim ThisBook as Workbook Set ThisBook=ActiveWorkbook When I open a second workbook for data: Dim DataBook as Workbook Set DataBook=ActiveWorkbook Now I simply use the workbook variables to qualify which range form which workbook to use. -- Rod Gill Project MVP NEW!! Project VBA Book, for details visit: http://www.projectvbabook.com "Jason" wrote in message ... I am trying to use some code to copy and paste a variety of cells from a master workbook ("WB1", which contains the code) to a second WB ("WB2"). The name of WB1 is fixed and will not change. However, WB2 will not always have the same filename. I would generally only be doing this one workbook at a time, i.e. I will have WB1 open along with WB2, and then run the code. Is there a way using code to reference/activate WB2 while I am in WB1 without having to use the filename of WB2 (it will not always be the same)? Thanks. -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Activating Workbook | Excel Programming | |||
Activating a workbook | Excel Programming | |||
activating a workbook | Excel Programming | |||
Open workbook without activating it | Excel Programming | |||
Activating a workbook help | Excel Programming |