ActiveWorkBook

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
 
N

Nick Hodge

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top