#CTTUTORIAL
How to Loop through Sheets in a Workbook in Excel VBA (Macros) - Code Included||VBA to Loop Through All Worksheets in a workbook
Macro to Loop Through All Worksheets in a Workbook. We use a for each worksheet in worksheets to loop through each sheet in a workbook.
This Excel VBA Tutorial shows VBA Code to loop through worksheets in a workbook. Use For Loop for each tab to perform task on multiple sheets.
Code:
Sub Loops_Through_Books_Sheets()
'For Checking all the open workbooks
Dim book As Workbook, sheet As Worksheet, text As String
For Each book In Workbooks
text = text & "Workbook: " & book.Name & vbNewLine & vbNewLine & "Worksheets: " & vbNewLine
'For getting worksheets name of all the open workbooks
For Each sheet In book.Worksheets
text = text & sheet.Name & vbNewLine
Next sheet
Next book
MsgBox text
End Sub