none
Change CodeName of Worksheet via VBA in Excel RRS feed

  • Question

  • Hello,

    I Am looking for a solution, where I will be able to change the CodeName of worksheet.

    I know, that is possible to do manually in sheet properties, but I want to use macro or default option. I tried some code below, but without any good result.

    This code gives you the name of active worksheet - MsgBox Worksheets(ActiveSheet.Index).CodeName

    So, I tried to rename like this, but it didn’t work - Worksheets(ActiveSheet.Index).CodeName = "NovyNazev"


    VALL2

    Friday, January 17, 2014 8:16 AM

Answers

  • This requires a reference to MS VBA extensibility in your project:

        Dim sNewName As String
        sNewName = "NovyNazev"

        With Worksheets(ActiveSheet.Index)
            .Parent.VBProject.VBComponents(.CodeName) _
                    .Properties("_CodeName") = sNewName
        End With


    Friday, January 17, 2014 6:40 PM