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!
Bookmarks