Extract Sheet Names from code module

visuvisu

New Member
Joined
Jan 11, 2025
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Sub ExtractSheetNames()
Dim VBProj As Object
Dim VBComp As Object
Dim Code As String
Dim Line As String
Dim i As Integer
Dim StartPos As Integer
Dim EndPos As Integer
Dim SheetName As String

Set VBProj = ThisWorkbook.VBProject
Set VBComp = VBProj.VBComponents("ModuleName")
Code = VBComp.CodeModule.Lines(1, VBComp.CodeModule.CountOfLines)
For i = 1 To VBComp.CodeModule.CountOfLines
Line = VBComp.CodeModule.Lines(i, 1)
If InStr(Line, "Sheets(") > 0 Or InStr(Line, "Worksheets(") > 0 Then
StartPos = InStr(Line, "(") + 2
EndPos = InStr(Line, ")") - 1
SheetName = Mid(Line, StartPos, EndPos - StartPos)
SheetName = Replace(SheetName, Chr(34), "")
Debug.Print "Found Sheet: " & SheetName
End If
Next i
End Sub
 

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top