» Change the worksheet codemodule names using VBA in Microsoft Excel
VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
CATEGORY - Files, Workbook, and Worksheets in VBA
VERSION - All Microsoft Excel Versions
The macro below can be used to rename the codemodules using names like Sheet1, Sheet2, Sheet3, Sheet4, Sheet5 and so on.
Sub ChangeAllWorksheetCodenames()
' requires a reference to the Visual Basic Extensibility library
Dim ws As Worksheet, i As Integer
If TypeName(ActiveWorkbook) = "Nothing" Then Exit Sub
' assign a temporary name to avoid naming conflicts
i = 0
For Each ws In ActiveWorkbook.Worksheets
i = i + 1
On Error Resume Next
ws.Parent.VBProject.VBComponents(ws.CodeName).Properties("_CodeName") = _
"fubar" & i
On Error GoTo 0
Next ws
' assign the proper name
i = 0
For Each ws In ActiveWorkbook.Worksheets
i = i + 1
On Error Resume Next
ws.Parent.VBProject.VBComponents(ws.CodeName).Properties("_CodeName") = _
"Sheet" & i
On Error GoTo 0
Next ws
Set ws = Nothing
End Sub
Book Store:
Recommended Books:
- Monte Carlo Methods in Finance
- The Interpretation of Financial Statements
- Microsoft Outlook Version 2002 Step by Step (With CD-ROM)
- Rich Dad's Guide to Investing: What the Rich Invest in, That the Poor and the Middle Class Do Not!
- The Sweet Potato Queens' Big-Ass Cookbook and Financial Planner
- The Essential 55: An Award-Winning Educator's Rules for Discovering the Successful Student in Every Child
No comments have been submitted.


