Rename Built-In Styles

G

Gillette Kempf

I want to rename Word's built-in style names to remove the spaces
(this will assist in importing documents into RoboHelp). I found a
nifty post with macro by Klaus Linke dated 04-12-2002 -- however only
the first part of the macro is working. I am not a VBA expert, so I am
not sure what is missing from the code. If anyone can assist with
this I would appreciate it.

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

<<I believe this is the point at which the macro stops working>>

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


Thanks again for all the assistance I have received at various times
from the great people on this list <g>.

Gillette
 
J

Jezebel

I think that code is not going to do what you want. What it aims to do is
save the document as an RTF file, then modify the style names within the
RTF. However the Word built-in style names are truly that: built-in. If you
get the macro to work, you'll end up with two lots of styles. The built-ins
PLUS your renamed styles.

Find a way to work with the built-in names -- a lot of Word's functionality
is dependent on them.
 
K

Klaus Linke

Hi Gillette,

The macro still seems to run fine for me in Word2002. What version are you
using, and what goes wrong (error message, not the desired result...)?

Greetings,
Klaus
 
K

Klaus Linke

Hi Jezebel,

However the Word built-in style names are truly that: built-in. If you
get the macro to work, you'll end up with two lots of styles.
The built-ins PLUS your renamed styles.

I am the first to agree that it's a good idea to use the built-in styles.
But nobody *forces* you to use "Normal" and the built-in heading styles...

Once you have a document using these styles, it's not easy to get rid of
them.
You can use "Find/Replace", but this will remove any manual paragraph
formatting that you have applied (such as "Page break before").

So there is some redeeming value to the macro, I think ;-)

Find a way to work with the built-in names -- a lot of Word's functionality
is dependent on them.

I've been in Gillette's situation, too. If you want to convert the document
for a DTP program or some other program, the blanks in the style names may
be a no-no. And since the doc is taken out of Word anyway, there's no reason
to stay with the built-in styles.

BTW, @Gilette: The macro closes the document, and opens a new one with the
changed style names.
Have you looked at the style names? No offence meant, but maybe the macro
already *did* it's dirty work.

Greetings,
Klaus
 
J

Jezebel

You're right that no-one forces you. I wasn't trying to make an issue of
this. But Word itself reverts to the built-in styles at the drop of a hat.
Seems to me that trying to avoid normal, heading 1, etc, although indeed
possible, is a sure road to strabismus, insanity, and death. (well not
quite, perhaps, but you catch my drift, I'm sure.)

cheers
J
 
G

Gillette Kempf

I am running Word 2002 as well. Perhaps I am not understanding the
results of the macro. When I run the macro I have a new file with the
RTF extension, when I open the RTF file, I see the same style names
with no asterisks and when I try to change the style names to remove
the spaces, I still get aliasing. Therefore, perhaps incorrectly, I
guessed that the macro paused after closing the RTF file.

Thanks again,

Gillette
 
G

Gillette Kempf

Hello All,

Well I finally did get the macro to work. I was running the macro out
of the template where I saved the macro. However, when I created a new
document based on the template and ran the macro, it worked Just Fine!
Silly me <g>

Macros Rule!

Gillette
 
Top