Results 1 to 4 of 4
  1. #1
    5 Star Lounger
    Join Date
    May 2001
    Stuttgart, Baden-W, Germany
    Thanked 0 Times in 0 Posts

    Get rid of (renaming) built-in styles (Word 2000)

    At times it is a nuisance that built-in styles (like <font face="Comic Sans MS">Normal</font face=comic> or <font face="Comic Sans MS">heading 1</font face=comic>) can't be renamed in Word.

    Say you want to copy parts of one document into another with different style definitions, but want to keep the formatting. This is nearly impossible if both documents use built-in styles, because you can not rename the styles in one of the documents. So a paragraph formatted in <font face="Comic Sans MS">Normal</font face=comic> style will acquire the formatting of <font face="Comic Sans MS">Normal</font face=comic> in the document you paste into, and there is not much you can do about it (short of using "paste special" as a Word document object).

    Another case where I found this a nuisance is when I take Word documents into a DTP program. Say the chapter headings in the DTP program are supposed to have style <font face="Comic Sans MS">H1</font face=comic>. Then I have to rename <font face="Comic Sans MS">heading 1</font face=comic> in the DTP program, which often has to be done manually.
    A macro solution in Word would be preferable.

    The following macro renames all styles in the document by appending a * to the style name (<font face="Comic Sans MS">heading 1</font face=comic> is changed to <font face="Comic Sans MS">heading 1*</font face=comic> ...).
    Since <font face="Comic Sans MS">heading 1*</font face=comic> isn't recognized as a built-in style anymore, I can then rename it to anything I want (for example to <font face="Comic Sans MS">H1</font face=comic>).

    The macro works by saving the file in RTF format, and changing all style names in the header of the RTF file.

    Hope somebody else will find this useful, too.
    The usual disclaimer: Use the macro at your own risk <img src=/S/wink.gif border=0 alt=wink width=15 height=15>

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Klaus

    <pre>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 If

    myFileName = ActiveDocument.Name
    If InStr(1, myFileName, ".") > 0 Then
    myFileName = Left$(myFileName, InStr(1, myFileName, ".")) & "RTF"
    myFileName = myFileName & ".RTF"
    End If
    ActiveDocument.SaveAs _
    FileName:=myFileName, _
    Documents.Open _
    FileName:=myFileName, _
    ConfirmConversions:=False, _
    Set myRange = ActiveDocument.Content
    myRange.Find.Execute _
    FindText:="{stylesheet*}}", _
    myRange.Find.Execute _
    FindText:=";}", _
    ReplaceWith:="*^&", _
    MatchWildcards:=True, _
    Documents.Open _
    End Sub</pre>

  2. #2
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Sun Prairie, Wisconsin, Wisconsin, USA
    Thanked 113 Times in 110 Posts

    Re: Get rid of (renaming) built-in styles (Word 2000)

    Attached is your macro as a zipped .bas file. When I tried pasting from the board listing, all of the carriage returns were stripped out. Figured I would save someone else the trouble of putting them back in.

    BTW, WOPR includes a utility to duplicate a style.
    Attached Files Attached Files
    Charles Kyle Kenyon
    Madison, Wisconsin

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Hollywood (sorta), California, USA
    Thanked 0 Times in 0 Posts

    Re: Get rid of (renaming) built-in styles (Word 2000)

    Nice routine. Thanks for posting this Klaus.

    I've been postponing the task of copying some styles (created by a user) into a template. Before I could let her know NOT to use the built-in H1, etc., she finished. Now it's my problem.

    So, I look forward to trying this out... <img src=/S/cool.gif border=0 alt=cool width=15 height=15>
    Kevin <IMG SRC= alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    Silver Lounger
    Join Date
    Jun 2001
    Morden, Surrey, United Kingdom
    Thanked 0 Times in 0 Posts

    Re: Get rid of (renaming) built-in styles (Word 2000)

    For future reference, someone here on the lounge once commented that if you want to copy code from the lounge to the VBE, you should just paste it into an ordinary Word doc first, then copy it out again and into the VBE.

    Works perfectly!
    Beryl M

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts