I have a macro that I run that removes/replaces all the symbols in part body names prior to running a part2product macro.
This macro works great because I receive some horrilby named parts from some of our custoemrs.
The only issue is that I replace the symbols with an underscore and sometimes I end up with an underscore at the end of the name.
I have done some digging and cant find the right code to be able to remove underscores from the end of the name.
If someone can please provide me with the correct code, it would be greatly appreicaticated.
Here is the current code I have:
This macro works great because I receive some horrilby named parts from some of our custoemrs.
The only issue is that I replace the symbols with an underscore and sometimes I end up with an underscore at the end of the name.
I have done some digging and cant find the right code to be able to remove underscores from the end of the name.
If someone can please provide me with the correct code, it would be greatly appreicaticated.
Here is the current code I have:
Code:
Sub CATMain()
CATIA.RefreshDisplay = False
Dim myPart As Part
Set myPart = CATIA.ActiveDocument.Part
Dim myBody As Body
Dim newName As String
Dim newCharacter As String
newCharacter = " "
For Each myBody In myPart.Bodies 'loop through all the bodies in the part
newName = myBody.name 'get the current body's name
newName = Replace(newName, ".", "_")
newName = Replace(newName, ",", "_")
newName = Replace(newName, "(", "_")
newName = Replace(newName, ")", "_")
newName = Replace(newName, "[", "_")
newName = Replace(newName, "]", "_")
newName = Replace(newName, "{", "_")
newName = Replace(newName, "}", "_")
newName = Replace(newName, "/", "_")
newName = Replace(newName, "\", "_")
newName = Replace(newName, "#", "_")
newName = Replace(newName, "$", "_")
newName = Replace(newName, "%", "_")
newName = Replace(newName, "*", "_")
newName = Replace(newName, " ", "_")
newName = Replace(newName, "____", "_")
newName = Replace(newName, "___", "_")
newName = Replace(newName, "__", "_")
myBody.name = newName 'rename the current body with the revised name
Next
MsgBox "All Done Removing Symbols From Part Body Names!"
Call Rename_Duplicate_Parts
End Sub