Note that changing the codename requires security settings that allow access
to the VB Project (Tools menu > Macro > Security... > Trusted Publishers tab
> check 'Trust access to Visual Basic project'.
- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. -
http://PeltierTech.com
_______
"Peter T" <peter_t@discussions> wrote in message
news:(E-Mail Removed)...
> I'm not quite sure how to interpret the subject line but perhaps you might
> look into changing the CodeName. This is the name you see in the VBE that
> precedes the 'tab' name in brackets.
>
> There are problems though returning the codename of a newly inserted sheet
> while the VBE is closed and until the wb has been saved. There are more
> issues to address renaming the codename without security access to Visual
> Basic Project. The codename can only be changed in the VBE or with code.
> You
> probably don't need to change the codename, just record and store the
> 'given' codename for future reference in case user renames sheet or
> changes
> tab-order.
>
> For what I think is the main purpose of your thread try something like
> this
>
> Sub test()
> Dim wsCopy As Worksheet, wsNew As Worksheet
> Dim wsAfter As Worksheet
>
> ' assumes the wb contains a sheet named "My Template"
>
> Set wsAfter = Worksheets(2) 'Sheets("2") ? change to suit
> NoSheetsReqd = 3
>
> For i = 1 To NoSheetsReqd
> Worksheets("My Template").Copy Before:=wsAfter
>
> Set wsNew = Worksheets(wsAfter.Index - 1)
>
> On Error Resume Next
> n = 0
> Do
> Err.Clear
> n = n + 1
> wsNew.Name = "New Sht Name_" & n
> Loop Until Err.Number = 0
> On Error GoTo 0
> Next i
>
> End Sub
>
> The copied sheet will exist in the index position it was copied to, so can
> be referenced by its known index as above. Also if pasting into the
> ActiveWorkbook, the newly copy/pasted sheet will be made the ActiveSheet,
> which would be a simpler way to reference it.
>
> Regards,
> Peter T
>
>
> "michael.beckinsale" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi All,
>>
>> Is there a way to change the sheet name Excel assigns to a sheet using
>> VBA? If so would anybody be kind enough to provide a code snippet?
>>
>> The code below copy's a sheet(s) and renames the tab but l want to
>> also rename the name assigned by Excel. A further problem is that l
>> dont know how to identify the sheet name that Excel has assigned to
>> the newly copied sheet!
>>
>>
>> For i = 1 To NoSheetsReqd
>> Sheets("My Template").Copy Before:=Sheets("2")
>> Sheets("My Template (2)").Select
>> Sheets("My Template (2)").Name = "New Sht Name"
>> Next i
>>
>> All help gratefully appreciated.
>>
>> For the curious l am building a solution where complete control of the
>> worksheets order & positioning is needed but it is desirable for the
>> end-user to be able to change the tab name to make it easily
>> identifiable to them, ie not just a number, so l can then use Excels
>> assigned names to control the order, positioning etc.
>>
>>
>> Regards
>>
>> MB
>>
>
>