+ Reply to Thread
Results 1 to 3 of 3

Macro to have user enter new worksheet name

  1. #1
    MMH
    Guest

    Macro to have user enter new worksheet name

    Hello all

    At the end of my macro, I want the user to rename the active worksheet. Is
    there some way I can do this in VBA.

    Failing that, how would I get a message box to appear reminding the user
    they need to change the worksheet name.

    Thank you in advance.
    MMH

  2. #2
    JE McGimpsey
    Guest

    Re: Macro to have user enter new worksheet name

    One way:

    Public Sub RenameSheet()
    Dim vNewName As Variant
    With ActiveSheet
    Do
    vNewName = Application.InputBox( _
    Prompt:="Enter new worksheet name:", _
    Title:="Rename Worksheet", _
    Type:=2)
    If vNewName = False Then Exit Sub 'user cancelled
    If UCase(vNewName) = UCase(.Name) Then
    vNewName = ""
    ElseIf Len(Trim(vNewName)) > 0 Then
    On Error Resume Next
    .Name = vNewName
    On Error GoTo 0
    End If
    Loop Until .Name = vNewName
    End With
    End Sub


    In article <[email protected]>,
    MMH <[email protected]> wrote:

    > At the end of my macro, I want the user to rename the active worksheet. Is
    > there some way I can do this in VBA.
    >
    > Failing that, how would I get a message box to appear reminding the user
    > they need to change the worksheet name.


  3. #3
    MMH
    Guest

    Re: Macro to have user enter new worksheet name

    Thank you, that did exactly what I wanted.

    MMH

    "JE McGimpsey" wrote:

    > One way:
    >
    > Public Sub RenameSheet()
    > Dim vNewName As Variant
    > With ActiveSheet
    > Do
    > vNewName = Application.InputBox( _
    > Prompt:="Enter new worksheet name:", _
    > Title:="Rename Worksheet", _
    > Type:=2)
    > If vNewName = False Then Exit Sub 'user cancelled
    > If UCase(vNewName) = UCase(.Name) Then
    > vNewName = ""
    > ElseIf Len(Trim(vNewName)) > 0 Then
    > On Error Resume Next
    > .Name = vNewName
    > On Error GoTo 0
    > End If
    > Loop Until .Name = vNewName
    > End With
    > End Sub
    >
    >
    > In article <[email protected]>,
    > MMH <[email protected]> wrote:
    >
    > > At the end of my macro, I want the user to rename the active worksheet. Is
    > > there some way I can do this in VBA.
    > >
    > > Failing that, how would I get a message box to appear reminding the user
    > > they need to change the worksheet name.

    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1