Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Activating Workbook

If you have only WB1 and one other (visible) workbook open, you can use code
like

Dim WB1 As Workbook
Dim WB As Workbook
For Each WB In Workbooks
If WB.Windows(1).Visible = True Then
If WB.Name < ThisWorkbook.Name Then
Set WB1 = WB
Exit For
End If
End If
Next WB

Debug.Print WB.Name


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

"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: 367
Default Activating Workbook

Chip, I am not sure I follow. I've pasted my code to give a better
understanding of what I want to do. How would I integrate your suggestion to
make it work?

Workbooks("WB1").Activate
Sheets("Sheet1").Activate
Range("K20").Copy

Workbooks("Unknown Name").Activate

' This is where I am getting hung up. Given that I don't know what the
name of the workbook will be (it is always changing), I don't know how to
activate it so that I can toggle between the two workbooks

Sheets("Sheets1").Activate
Range("K20").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

Workbooks("WB1").Activate
Sheets("Sheet1").Activate
Range("A13").Copy

This process will continue on as I copy and paste a number of cells from one
workbook to another.



"Chip Pearson" wrote:

If you have only WB1 and one other (visible) workbook open, you can use code
like

Dim WB1 As Workbook
Dim WB As Workbook
For Each WB In Workbooks
If WB.Windows(1).Visible = True Then
If WB.Name < ThisWorkbook.Name Then
Set WB1 = WB
Exit For
End If
End If
Next WB

Debug.Print WB.Name


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

"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.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Activating Workbook

Jason,

Using the code I posted, you don't access the other, unknown workbook with

Workbooks("Unknown Name").Activate

Instead, the code I posted has a variable of type Workbook named WB1 that
will refer to the unknown workbook. Therefore, instead of

Workbooks("Unknown Name").Activate

you'd use

WB1.Activate

Or, if you prefer,

Workbooks(WB1.Name).Activate


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)




"Jason" wrote in message
...
Chip, I am not sure I follow. I've pasted my code to give a better
understanding of what I want to do. How would I integrate your suggestion
to
make it work?

Workbooks("WB1").Activate
Sheets("Sheet1").Activate
Range("K20").Copy

Workbooks("Unknown Name").Activate

' This is where I am getting hung up. Given that I don't know what the
name of the workbook will be (it is always changing), I don't know how to
activate it so that I can toggle between the two workbooks

Sheets("Sheets1").Activate
Range("K20").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

Workbooks("WB1").Activate
Sheets("Sheet1").Activate
Range("A13").Copy

This process will continue on as I copy and paste a number of cells from
one
workbook to another.



"Chip Pearson" wrote:

If you have only WB1 and one other (visible) workbook open, you can use
code
like

Dim WB1 As Workbook
Dim WB As Workbook
For Each WB In Workbooks
If WB.Windows(1).Visible = True Then
If WB.Name < ThisWorkbook.Name Then
Set WB1 = WB
Exit For
End If
End If
Next WB

Debug.Print WB.Name


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

"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.






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 367
Default Activating Workbook

That worked perfectly. Thanks to all for your responses.

Jason


"Chip Pearson" wrote:

Jason,

Using the code I posted, you don't access the other, unknown workbook with

Workbooks("Unknown Name").Activate

Instead, the code I posted has a variable of type Workbook named WB1 that
will refer to the unknown workbook. Therefore, instead of

Workbooks("Unknown Name").Activate

you'd use

WB1.Activate

Or, if you prefer,

Workbooks(WB1.Name).Activate


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)




"Jason" wrote in message
...
Chip, I am not sure I follow. I've pasted my code to give a better
understanding of what I want to do. How would I integrate your suggestion
to
make it work?

Workbooks("WB1").Activate
Sheets("Sheet1").Activate
Range("K20").Copy

Workbooks("Unknown Name").Activate

' This is where I am getting hung up. Given that I don't know what the
name of the workbook will be (it is always changing), I don't know how to
activate it so that I can toggle between the two workbooks

Sheets("Sheets1").Activate
Range("K20").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

Workbooks("WB1").Activate
Sheets("Sheet1").Activate
Range("A13").Copy

This process will continue on as I copy and paste a number of cells from
one
workbook to another.



"Chip Pearson" wrote:

If you have only WB1 and one other (visible) workbook open, you can use
code
like

Dim WB1 As Workbook
Dim WB As Workbook
For Each WB In Workbooks
If WB.Windows(1).Visible = True Then
If WB.Name < ThisWorkbook.Name Then
Set WB1 = WB
Exit For
End If
End If
Next WB

Debug.Print WB.Name


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

"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.






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 a workbook Boldie Excel Programming 5 July 19th 06 03:15 AM
Activating previously used workbook Ozgur Pars[_2_] Excel Programming 6 May 10th 06 06:58 AM
activating a workbook VB Script for Excel Excel Programming 12 March 22nd 06 07:55 AM
Activating workbook with variable Name Mark Klaus Excel Programming 2 October 24th 03 10:41 PM
Activating a workbook help bmwmcrider Excel Programming 1 October 21st 03 01:48 PM


All times are GMT +1. The time now is 04:32 AM.

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"