Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default Setting the CodeName of a new worksheet in the VBE Editor

Hi,

When I programatically add a new worksheet in VBA, is there a way to
programatically set the CodeName property ...

So instead of showing as Sheet1 in the VB Editor 'Project Explorer', the new
sheet shows as what I want it to be.

This is for Excel 2003

thanks for any help

Philip
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Setting the CodeName of a new worksheet in the VBE Editor

Paul,

When the sheet is created it is the active sheet so this should be the next
line after creation.

ActiveSheet.Name = "Your Name"

Mike

"Philip" wrote:

Hi,

When I programatically add a new worksheet in VBA, is there a way to
programatically set the CodeName property ...

So instead of showing as Sheet1 in the VB Editor 'Project Explorer', the new
sheet shows as what I want it to be.

This is for Excel 2003

thanks for any help

Philip

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Setting the CodeName of a new worksheet in the VBE Editor

Hi Philip,

To change the sheet's codename, try something like:

'=============
Public Sub Tester()
ThisWorkbook.VBProject.VBComponents _
(Worksheets("Sheet2").CodeName).Name = "aName"
End Sub
'<<=============


---
Regards,
Norman


"Philip" wrote in message
...
Hi,

When I programatically add a new worksheet in VBA, is there a way to
programatically set the CodeName property ...

So instead of showing as Sheet1 in the VB Editor 'Project Explorer', the
new
sheet shows as what I want it to be.

This is for Excel 2003

thanks for any help

Philip



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Setting the CodeName of a new worksheet in the VBE Editor

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


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Philip" wrote in message
...
Hi,

When I programatically add a new worksheet in VBA, is there a way to
programatically set the CodeName property ...

So instead of showing as Sheet1 in the VB Editor 'Project Explorer', the
new
sheet shows as what I want it to be.

This is for Excel 2003

thanks for any help

Philip



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default Setting the CodeName of a new worksheet in the VBE Editor

Thanks all,

In the end I found it was fairly simple like this:
thisworkbook.VBProject.VBComponents("Sheet1").Name = "Phil"

Philip

"Norman Jones" wrote:

Hi Philip,

To change the sheet's codename, try something like:

'=============
Public Sub Tester()
ThisWorkbook.VBProject.VBComponents _
(Worksheets("Sheet2").CodeName).Name = "aName"
End Sub
'<<=============


---
Regards,
Norman


"Philip" wrote in message
...
Hi,

When I programatically add a new worksheet in VBA, is there a way to
programatically set the CodeName property ...

So instead of showing as Sheet1 in the VB Editor 'Project Explorer', the
new
sheet shows as what I want it to be.

This is for Excel 2003

thanks for any help

Philip






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Setting the CodeName of a new worksheet in the VBE Editor

Hi Philip

Try below, please.


Option Explicit


Sub CodeName()
'// Codename
ThisWorkbook.VBProject.VBComponents(ActiveSheet.Co deName) _
.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


--
Best regards
Joergen Bondesen


"Philip" wrote in message
...
Hi,

When I programatically add a new worksheet in VBA, is there a way to
programatically set the CodeName property ...

So instead of showing as Sheet1 in the VB Editor 'Project Explorer', the
new
sheet shows as what I want it to be.

This is for Excel 2003

thanks for any help

Philip




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting a Worksheets Codename to a variable programmatically Turk[_3_] Excel Programming 3 October 19th 06 01:25 PM
? Get Worksheet Codename List gabch[_10_] Excel Programming 1 April 11th 06 12:33 PM
Calling a worksheet via a codename Thierry Paradis Excel Programming 2 March 2nd 06 02:41 PM
Using Worksheet Codename to Determine Worksheet Existence David Copp[_3_] Excel Programming 4 July 2nd 04 08:00 AM
Worksheet codename Andy Excel Programming 4 December 2nd 03 04:12 PM


All times are GMT +1. The time now is 08:51 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"