PC Review


Reply
Thread Tools Rate Thread

Change default number to default text?

 
 
StargateFanNotAtHome@mailinator.com
Guest
Posts: n/a
 
      1st Apr 2009
Having some difficulties figuring out how to change some default
text. After a few minutes, figured out that "default text" would
bring up better hits in googling this group but nothing comes up that
I can work with since I am rather limited in my vb abilities.

I have this script that was a kind gift a couple of years ago or so:
----------------------------------------
Sub NewSheet_Add()
Worksheets("TEMPLATE").Copy Before:=Worksheets(1)
Worksheets(1).Visible = xlSheetVisible
ActiveSheet.Unprotect 'place at the beginning of the code

Dim vResponse As Variant
Do
vResponse = Application.InputBox( _
Prompt:="Enter a name for the new tab.", _
Title:="Tab Name", _
Default:=Format(Day(Date), "000000"), _
Type:=2)
If vResponse = False Then Exit Sub 'User cancelled
Loop Until vResponse <> 0 And vResponse < 1000000
With Range("A2")
.NumberFormat = "000000"
.Value = vResponse
End With

On Error GoTo CanNotRename
ActiveSheet.Name = Format(vResponse, "000000")
On Error GoTo 0
Exit Sub

'Error code
CanNotRename:
MsgBox "Can't rename sheet to " & Format(vResponse, "000000")
Resume Next

ActiveSheet.Protect ' place at end of code
End Sub
----------------------------------------

It allows me to "start" a new sheet and then name it right then and
there. But the naming convention was a number. I need text with the
default text being, say, "Tab ", just to give an example

How can I change the above to reflect a new format for the tab name,
pls?

Thanks! D
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      1st Apr 2009
Hi,

Maybe something like this

Sub NewSheet_Add()
Worksheets("TEMPLATE").Copy Before:=Worksheets(1)
Worksheets(1).Visible = xlSheetVisible
ActiveSheet.Unprotect 'place at the beginning of the code

Dim vResponse As Variant
Do
vResponse = Application.InputBox( _
Prompt:="Enter a name for the new tab.", _
Title:="Tab Name", _
Default:="Tab", _
Type:=2)
If vResponse = False Then Exit Sub 'User cancelled
Loop Until vResponse <> ""
With Range("A2")
.Value = vResponse
End With

On Error GoTo CanNotRename
ActiveSheet.Name = Format(vResponse, "000000")
On Error GoTo 0
Exit Sub

'Error code
CanNotRename:
MsgBox "Can't rename sheet to " & vResponse
Resume Next

ActiveSheet.Protect ' place at end of code
End Sub


Mike

"(E-Mail Removed)" wrote:

> Having some difficulties figuring out how to change some default
> text. After a few minutes, figured out that "default text" would
> bring up better hits in googling this group but nothing comes up that
> I can work with since I am rather limited in my vb abilities.
>
> I have this script that was a kind gift a couple of years ago or so:
> ----------------------------------------
> Sub NewSheet_Add()
> Worksheets("TEMPLATE").Copy Before:=Worksheets(1)
> Worksheets(1).Visible = xlSheetVisible
> ActiveSheet.Unprotect 'place at the beginning of the code
>
> Dim vResponse As Variant
> Do
> vResponse = Application.InputBox( _
> Prompt:="Enter a name for the new tab.", _
> Title:="Tab Name", _
> Default:=Format(Day(Date), "000000"), _
> Type:=2)
> If vResponse = False Then Exit Sub 'User cancelled
> Loop Until vResponse <> 0 And vResponse < 1000000
> With Range("A2")
> .NumberFormat = "000000"
> .Value = vResponse
> End With
>
> On Error GoTo CanNotRename
> ActiveSheet.Name = Format(vResponse, "000000")
> On Error GoTo 0
> Exit Sub
>
> 'Error code
> CanNotRename:
> MsgBox "Can't rename sheet to " & Format(vResponse, "000000")
> Resume Next
>
> ActiveSheet.Protect ' place at end of code
> End Sub
> ----------------------------------------
>
> It allows me to "start" a new sheet and then name it right then and
> there. But the naming convention was a number. I need text with the
> default text being, say, "Tab ", just to give an example
>
> How can I change the above to reflect a new format for the tab name,
> pls?
>
> Thanks! D
>

 
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
How do I change default number format? dwayne1017 Microsoft Excel Misc 2 23rd Jul 2009 02:23 PM
default "plain text" message format when sending files. How to change default? Wim Eising Microsoft Outlook Discussion 5 14th Nov 2005 01:11 PM
Change Default Number =?Utf-8?B?cmljbw==?= Microsoft Access 4 22nd Feb 2005 01:13 PM
How to change the default view of an e-mail message to "web layout" when I reply to messages? The default view is Normal now. The text uses left one third of the screen only. Dmitriy Kopnichev Microsoft Outlook Discussion 0 26th Jan 2004 10:27 AM
How to change the default view of an e-mail message to "web layout" when I reply to messages? The default view is Normal now. The text uses left one third of the screen only. Dmitriy Kopnichev Microsoft Outlook 0 26th Jan 2004 10:27 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:42 AM.