Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
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
Activating Workbook Chip Pearson Excel Programming 3 December 30th 06 01:53 AM
Activating a workbook Boldie Excel Programming 5 July 19th 06 03:15 AM
activating a workbook VB Script for Excel Excel Programming 12 March 22nd 06 07:55 AM
Open workbook without activating it Kelley[_2_] Excel Programming 3 October 29th 03 04:49 PM
Activating a workbook help bmwmcrider Excel Programming 1 October 21st 03 01:48 PM


All times are GMT +1. The time now is 11:36 PM.

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"