Hi Philip
Try below, please.
Option Explicit
Sub CodeName()
'// Codename
ThisWorkbook.VBProject.VBComponents(ActiveSheet.CodeName) _
.Name = "Philip"
End Sub
Sub SheetVBAname()
Dim ShVBAname As String
MsgBox "VBA codename is: " & vbCr & ActiveSheet.CodeName
End Sub
' <<<<
Option Explicit
Sub TESTSheetAddNameCodeName()
Dim NewShName As String '***
Dim NewShCodeName As String '***
Dim sh As Worksheet
Dim ws As Worksheet
NewShName = "Philip"
NewShCodeName = "PhilipVBA"
SheetAddNameCodeName NewShName, NewShCodeName
End Sub
'----------------------------------------------------------
' Procedure : SheetAddNameCodeName
' Date : 20060312
' Author : Joergen Bondesen
' Modifyed by :
' Purpose :
' Note :
'----------------------------------------------------------
'
Function SheetAddNameCodeName(NewShName As String, _
NewShCodeName As String)
Dim sh As Worksheet
Dim ws As Worksheet
'// Controle for codename
For Each sh In ThisWorkbook.Sheets
If sh.CodeName = NewShCodeName Then
MsgBox "Codename exist. Macro will terminate."
End
End If
Next sh
'// Check to see if Sheet exists and if not, create it.
On Error Resume Next
Set ws = Worksheets(NewShName)
On Error GoTo 0
If ws Is Nothing Then
Set ws = Worksheets.Add
ws.Name = NewShName
On Error Resume Next
ws.Parent.VBProject.VBComponents(ws.CodeName) _
.Properties("Name") = NewShName
Application.DisplayAlerts = False
If Err <> 0 Then ws.Delete
Application.DisplayAlerts = True
On Error GoTo 0
Else
MsgBox "Sheet name exist. Macro will terminate."
End
End If
'// Codename
ThisWorkbook.VBProject.VBComponents _
(ActiveSheet.CodeName).Name = NewShCodeName
End Function