PC Review


Reply
Thread Tools Rate Thread

change code name

 
 
sunilpatel
Guest
Posts: n/a
 
      10th Jun 2009
To prevent user changing sheet name i intend referencing with codenames.
Hence the code below, which creates new sheets from Templates. But it does
not work when VBA Project is locked.
I cannot lock workbook as the worksheets are interactive.

So how does on get round this problem?


Sub CREATESHEETS()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Sheets
If Right$(sh.NAME, 4) = "TEMP" Then
L% = InStr(sh.NAME, "TEMP")
NEWSHEETNAME = Left$(sh.NAME, L% - 1) & ROW%
NEWCODE = Replace(NEWSHEETNAME, " ", "")
Sheets(sh.NAME).Copy After:=Sheets(Sheets.Count)
OLDCODE = ActiveSheet.CODENAME
ThisWorkbook.VBProject.VBComponents(OLDCODE).NAME = NEWCODE
ActiveSheet.NAME = NEWSHEETNAME
End If
Next sh
End Sub







 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      10th Jun 2009
Hi

If you protect the workbook for structure, user can not change sheet
names...

ActiveWorkbook.Protect Structure:=True, Windows:=False

Hopes this helps.

---
Per


On 10 Jun., 18:44, "sunilpatel" <sunilpa...@talktalk.net> wrote:
> To prevent user changing sheet name i intend referencing with codenames.
> Hence the code below, which creates new sheets from Templates. But it does
> not work when VBA Project is locked.
> I cannot lock workbook as the worksheets are interactive.
>
> So how does on get round this problem?
>
> Sub CREATESHEETS()
> Dim sh As Worksheet
> For Each sh In ActiveWorkbook.Sheets
> If Right$(sh.NAME, 4) = "TEMP" Then
> L% = InStr(sh.NAME, "TEMP")
> NEWSHEETNAME = Left$(sh.NAME, L% - 1) & ROW%
> NEWCODE = Replace(NEWSHEETNAME, " ", "")
> Sheets(sh.NAME).Copy After:=Sheets(Sheets.Count)
> OLDCODE = ActiveSheet.CODENAME
> ThisWorkbook.VBProject.VBComponents(OLDCODE).NAME = NEWCODE
> ActiveSheet.NAME = NEWSHEETNAME
> End If
> Next sh
> End Sub


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run VBA code only worksheet change, but don't trigger worksheet_change event based on what the code does ker_01 Microsoft Excel Programming 6 3rd Oct 2008 09:45 PM
Code to change code in a sheet and workbook module Otto Moehrbach Microsoft Excel Programming 11 11th Nov 2007 07:20 PM
Code Conflicts With Worksheet Change Code =?Utf-8?B?UGFpZ2U=?= Microsoft Excel Programming 3 3rd Mar 2006 04:25 PM
re: How to change grey code to change a DRW results column to a currency value Jim Buyens Microsoft Frontpage 0 25th May 2004 05:24 PM
how do I dynamically change an html meta tag from my code behind code? ntm Microsoft ASP .NET 2 19th Jan 2004 05:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:38 PM.