ActiveWorkBook

  • Thread starter Thread starter Pete
  • Start date Start date
P

Pete

Is there a Set ActiveWorkBook command available. I have 3 seperate
workbooks open at one time, I wish to perform actions via VBA on
different aspects of each workbook. How do I activate a specific
workbook.

Thanks

Pete
 
Pete

You don't need to activate anything to work on it. Set an object variable to
the workbooks as you open them like the code below

Sub CatchWBs()
Dim wb1 As Workbook, wb2 As Workbook, wb3 As Workbook

Set wb1 = Workbooks.Open("C:\Workbook1.xls")
Set wb2 = Workbooks.Open("C:\Workbook2.xls")
Set wb3 = Workbooks.Open("C:\Workbook3.xls")

'Just some random things to do with each workbook
wb1.PrintOut
wb2.PrintPreview
wb3.Protect

Set wb1 = Nothing
Set wb2 = Nothing
Set wb3 = Nothing

End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)
 
Back
Top