How to Cycle through open workbooks

  • Thread starter Thread starter Buster
  • Start date Start date
B

Buster

How do I cycle through the open workbooks and perform a vba script on each
one?
 
See the sample For Each-Next loop below:

Sub cycle()
Dim a As Object
For Each a In Workbooks
'do whatever you want to do here
a.Worksheets(1).Range("A1").Value = 1
Next
End Sub
 
Dim a As Object

Better to declare 'a' As Workbook since the Workbooks collection
contains only Workbooks.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

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

Back
Top