Results 1 to 5 of 5

VBA to Name Wkst - Help with Removing special char. & invalid names

Threaded View

  1. #1
    Registered User
    Join Date
    04-11-2012
    Location
    milwaukee, wi
    MS-Off Ver
    Excel 2007
    Posts
    11

    VBA to Name Wkst - Help with Removing special char. & invalid names

    Hi - I'm a VBA newbie, but am making a little progress. i have a macro (thanks to the help of this forum) to rename a wkst based on a cells value. It works great. But some of the cells have invalid wkst names, producing an error.

    I want it to fix invalid wkst names (remove special characters & shorten if too long, etc). I found a script to remove special characters, but don't know how to incorporate into my existing code or how to shorten the name if its too long.

    Existing Code:
    Private Sub Workbook_NewSheet(ByVal Sh As Object)
        Sh.Name = Sh.Range("P2")
    End Sub
    Code i want to incorporate to remove special characters (have not tested it)
    'letters only
    Function ReplaceSpecial(ByVal Txt As String) As String
    With CreateObject("VBScript.RegExp")
        .Pattern = "[^A-Z\s]+"
        .Global = True
        .IgnoreCase = True
        ReplaceSpecial = Application.Trim(.Replace(Txt, ""))
    End With
    End Function
    And then how would i get it to shorten to less than 32 characters?
    Millions of thanks!
    Last edited by popps; 04-17-2012 at 11:50 AM.

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