Vba loop through worksheet get name in Excel

To do it in Excel, here is the answer:

  1. Option Explicit
  2. Sub LoopThroughWorkSheets()
  3. Dim wrks As WorkSheet
  4. ''
  5. For Each wrks In ThisWorkBook.WorkSheets
  6. MsgBox wrks.Name
  7. Next wrks
  8. ''
  9. End Sub

Description:

a) Line 5 - "For each" can be used for looping through objects / controls in WorkSheet / WorkBook. In this case through the use of "ThisWorkBook.WorkSheets" it is used to loop through WorkSheets.

b) This is very useful when the macro has to loop through all WorkSheets and then process information from each or some of the WorkSheets.

 

You can find similar Excel Questions and Answer hereunder

1) How to print a worksheet in Excel VBA

2) How can I set non-contiguous print area using VBA?

3) How to handle errors in VBA with the handling error methods

4) How to add a link in a sheet to another sheet

5) Is there any way I can see more region of my WorkSheet?

6) How can I identify all cells with Conditional Formatting in my WorkSheet?

7) What are the various functions of the worksheet in Excel VBA

8) How can I avoid updates to cell values during macro execution?

9) How can I change the Marker size and Marker line color for all the series in a chart?

10) How to do loops in VBA with the while loop

 

Here the previous and next chapter