View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jason Jason is offline
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.