View Single Post
 
Old 01-30-2017, 08:45 AM
Kev Kev is offline Windows 7 64bit Office 2016
Novice
 
Join Date: Jan 2017
Posts: 7
Kev is on a distinguished road
Default

Another way to fix the problem would be to rename worksheets that contain non-valid characters
The VBA is currently set to display what happens via a message box - apostrophe is replaced with ~ and space replaced with _
To rename the worksheets remove the apostrophe at the beginning of this line
Code:
'ws.Name = newName
Code:
Sub remove_Spaces_and_Apostrophes()
    Dim oldName As String, newName As String, ws As Worksheet
    
    For Each ws In ThisWorkbook.Worksheets
    oldName = ws.Name
    newName = Replace(ws.Name, "'", "~")
    newName = Replace(newName, " ", "_")
    'build up message string
    msg = oldName & "   becomes   " & newName & vbCr & msg
    'replace the name
    'ws.Name = newName
Next

    MsgBox "Old Name   with     New Name" & vbCr & vbCr & msg

End Sub
Reply With Quote