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