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. |
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 |
All times are GMT +1. The time now is 07:24 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com