kamrad
07-01-2013, 12:52 AM
Hello fellows,
I am using Word 2010. I would like to change the names of the built-in styles in a document that I would then like to turn into a template. I found a script on the Web that is claimed to do that (sorry, not allowed post the link to this web page).
Sub ChangeStyleNames()
' The macro appends a * to all style names
' It thus changes built-in styles to ordinary styles
Dim myRange As Range
Dim MsgText
Dim myFileName
MsgText = "Cancel if you have not saved the file"
If MsgBox(MsgText, vbExclamation + vbOKCancel, "Danger") = vbCancel Then
End
End If
myFileName = ActiveDocument.Name
If InStr(1, myFileName, ".") > 0 Then
myFileName = Left$(myFileName, InStr(1, myFileName, ".")) & "RTF"
Else
myFileName = myFileName & ".RTF"
End If
ActiveDocument.SaveAs _
FileName:=myFileName, _
FileFormat:=wdFormatRTF
ActiveDocument.Close
Documents.Open _
FileName:=myFileName, _
ConfirmConversions:=False, _
Format:=wdOpenFormatText
Set myRange = ActiveDocument.Content
myRange.Find.Execute _
FindText:="{stylesheet*}}", _
MatchWildcards:=True
myRange.Find.Execute _
FindText:=";}", _
ReplaceWith:="*^&", _
MatchWildcards:=True, _
Replace:=wdReplaceAll
ActiveDocument.Save
ActiveDocument.Close
Documents.Open _
FileName:=myFileName
End Sub
According to the VB debugger, the faulty code part is the following:
myRange.Find.Execute _
FindText:="{stylesheet*}}", _
MatchWildcards:=True
Unfortunately, I am not familiar with VB. :dunno Could you please tell me what the problem is? The error message that I get says: "the Find What text contains a Pattern Match expression which is not valid".
Thank you for your help in advance! :hi:
I am using Word 2010. I would like to change the names of the built-in styles in a document that I would then like to turn into a template. I found a script on the Web that is claimed to do that (sorry, not allowed post the link to this web page).
Sub ChangeStyleNames()
' The macro appends a * to all style names
' It thus changes built-in styles to ordinary styles
Dim myRange As Range
Dim MsgText
Dim myFileName
MsgText = "Cancel if you have not saved the file"
If MsgBox(MsgText, vbExclamation + vbOKCancel, "Danger") = vbCancel Then
End
End If
myFileName = ActiveDocument.Name
If InStr(1, myFileName, ".") > 0 Then
myFileName = Left$(myFileName, InStr(1, myFileName, ".")) & "RTF"
Else
myFileName = myFileName & ".RTF"
End If
ActiveDocument.SaveAs _
FileName:=myFileName, _
FileFormat:=wdFormatRTF
ActiveDocument.Close
Documents.Open _
FileName:=myFileName, _
ConfirmConversions:=False, _
Format:=wdOpenFormatText
Set myRange = ActiveDocument.Content
myRange.Find.Execute _
FindText:="{stylesheet*}}", _
MatchWildcards:=True
myRange.Find.Execute _
FindText:=";}", _
ReplaceWith:="*^&", _
MatchWildcards:=True, _
Replace:=wdReplaceAll
ActiveDocument.Save
ActiveDocument.Close
Documents.Open _
FileName:=myFileName
End Sub
According to the VB debugger, the faulty code part is the following:
myRange.Find.Execute _
FindText:="{stylesheet*}}", _
MatchWildcards:=True
Unfortunately, I am not familiar with VB. :dunno Could you please tell me what the problem is? The error message that I get says: "the Find What text contains a Pattern Match expression which is not valid".
Thank you for your help in advance! :hi: