Loop though and process all open excel workbooks using VBA

The code below does the following:

  1. Loop though all open Excel workbooks in Excel
  2. Sequentially activate each of the workbook
  3. Do some processing related to the active workbook
  4. Save the workbook then move on to the next workbook
Sub Loop_through_all_workbooks()
   Dim wb As Workbook, x As String
   For Each wb In Workbooks
      If wb.Name  ThisWorkbook.Name Then
         x = wb.Name
         Workbooks(x).Activate
      End If 
      Call Do_some_actions() 
      Call ActiveWorkbook.Save
   Next wb 
End Sub 

Sub do_some_actions
   'here goes some code to be executed in the activeworkbook
End Sub
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s