• Heading styles Find and replace

    • This topic has 5 replies, 4 voices, and was last updated 15 years ago.
    Author
    Topic
    #468514

    hi

    I have a Word 2007 document. The document heading styles need to be updated to styles.

    Usually I perform a standard Find style “H2#” and Replace Style with “Sub Heading 2”
    This usually works.

    However with this document Im getting different results.

    When I Find and Replace heading styles, the result is replaces with the heading style ie “Sub Heading 2”.
    every other Sub heading 2 configuration is applied and replaced except for the font. The font remains as “Times New Roman”. The default font for Sub heading 2 is “Arial”. However after the Find, and replace the font remains as “Times New Roman”

    If I display the Style Pane, select the paragraph with style “H2#”, and in the task pane manually click on “Sub heading 2”. the result is “Sub heading 2” is applied with the correct font ie Arial.

    I was wanting an easier way than manually re-applying the style to each paragraph. The reason being is this document is approx. 200 pages and we’ll be receiving more types of this document.

    At first I thought it maybe different behaviour with Word 2007. However in WordXP I get the same behaviour

    Ive attached a sample doc to see if you could spot anything.

    many thanks

    diana

    Viewing 3 reply threads
    Author
    Replies
    • #1220972

      Hi Diana,

      The document appears to have a tremendous amount of direct formatting applied, and I think that in some way is interfering with the re-application of styles.

      Just to give one example (if you turn on Keep Track of Formatting and examine the list in the Styles and Formatting pane), you have a style called B1 that derives its Arial font from Normal style, and which is applied to 14 instances on the sample page. However there is no B1 text on the sample page that is in Arial font; all of the B1 text is in Times New Roman. And in the Styles pane, there are double listings of names like “B1 + Times New Roman, Auto” and “B1 + Times New Roman, Bold” that are applied as direct formatting, over all of the B1 paragraphs. And for some odd reason you’ve got one set of these direct format ‘styles’ set to Condensed by .1 pt, and the other set to not condensed.

      You’ve also got some numbered paragraphs that are just hard numbers, and other numbered paragraphs that are autonumbered, but which, as far as I can tell, represent “broken outlines”.

      There are also several “Char” styles, such as “Char”, “Char Char 1” etc.

      I think trying to reapply styles here is kind of like applying band-aids to a bunch of broken limbs – the document really needs to be stripped down from scratch and reformatted in a new clean shell based on the template (Select All, Copy, and the Paste Special > Unformatted Text into a new document, then reapply styles). If you anticipate needing to do lots of documents like these, you might look into automating some of the reformatting, if possible, but either way, I think the only way to fix this formatting is to start again from scratch.

      Also, you should examine the styles in the template itself, and make sure that the styles are set up cleanly and the autonumbering is set up correctly.

      Also, a question: The template is a .dotx, but the document is saved as a .doc – are you saving Word 2007 documents as .docs by default? Because if so, you’d probably be better off using .dot templates, even in Word 2007, since saving a .dotx-based document down to a .doc, removes anything 2007-related.

      Gary

    • #1220985

      I agree with Gary but I wouldn’t recommend going as far as a paste text only cleanup. I would select the entire content and remove all local formatting by pressing Ctrl-Q and Ctrl-Space. This would solve the specific problem you asked about and also resolve some of the other issues you will encounter in tidying up the document. I prefer this method to the paste text only because some of the style names are still useful for your search and replace functions. Also you will then have a large job to fix the automatic numbers which become hard-coded if you use the text only paste.

      One undesirable effect of both Gary’s and my suggestions is the loss of wanted local formatting such as the italicised words inside a paragraph.

      Another approach you could consider for reassigning styles on multiple documents is to make use of style aliases rather than the time consuming series of search and replaces. For instance, if you create a template where the style “Sub Heading 2” is renamed as “Sub Heading 2,H2#” then you could simply attach the template and refresh the styles to merge the two separate styles into the same look. This would be far quicker than running a series of search/replaces on each of the files. Code that would take care of attaching the template and refreshing the styles could be stored in your Normal.dotm template and look like this

      Code:
      Public Sub AttachMyTemplate()
      ' Macro created by Chrysalis Design
        Dim sTempPath As String
        sTempPath = Options.DefaultFilePath(wdUserTemplatesPath)
        With ActiveDocument
          .UpdateStylesOnOpen = False
          .AttachedTemplate = sTempPath & "MyTemplate.dotm"
        End With
        ActiveDocument.UpdateStyles
      End Sub
    • #1221124

      Many thanks Gary
      We’re currently in the process of upgrading from Office XP to Office 2007. For office 2007 the code has been converted to a .net solution The templates are .dotx. All documents are purposely saved as .doc to make compatiable with our clients. who would still be on older versions of office. At a later date when more firms have upgraded to Office 2007, another project exists to convert all .doc to docx.

      Andrew
      I like your “merging” the two heading styles together. a couple of things:
      If I create a new template and rename style “Sub heading 2” to “Sub heading 2,H2#”. In the template the heading style displays.
      If I open my doc and reattach to this new template the doc doesnt display this new heading style “Sub heading 2,H2#”. it displays a new heading style “Sub Heading Char”
      Have I missed a step?

      another method is:

      1. Turn on the view “Keep Track of formatting”. Goto Office button, select Word Options, select Advanced, tick checkbox “Keep Track of formatting”, click OK
      2. Display Styles Pane
      3. Select a paragraph. The Styles pane displays the heading style used
      4. On the Style arrow drop down, select “Select all instances(s). This is how many times this format has been applied
      5. This selects all those heading styles in the document
      6. In the Styles pane, scroll and locate sub heading 2. Click on Sub heading 2
      7. Result: this applies Sub heading 2 to all selected items.
      8. Repeat above steps for each heading style.
      9. Paragraphs will have to be checked and cleaned up eg if manual numbers have been typed in to replace automatic numbering
      This works.
      10. When completed untick the checkbox “Keep Track of formatting”. Goto Office button, select Word Options, select Advanced, untick checkbox “Keep Track of formatting”, click OK

      Note: This method takes a lot of memory processing therefore with large documents could choke Word and crash.

      • #1221126

        I create a new template and rename style “Sub heading 2” to “Sub heading 2,H2#”. In the template the heading style displays.
        If I open my doc and reattach to this new template the doc doesnt display this new heading style “Sub heading 2,H2#”. it displays a new heading style “Sub Heading Char”
        Have I missed a step?

        I think you might have missed the critical step of refreshing the styles – attaching the template doesn’t import the styles by itself. Note the two lines in the code I provided that mention update styles – These are the equivalent of ticking the “Automatically update document styles” in the Templates and Add-ins dialog, OK’ing the dialog and then going back in there and turning the tick box off and OK’ing the dialog a second time.

        Another possibility is the style name is not as you expected. In your original post you named a style as “Sub Heading 2” but the attached document showed the style was called “SubHeading 2”. My method would not work if the style name in the template wasn’t an exact match (including capitalisation and spaces) to the style name in the document.

        It is possible that the Char style corruption is the problem but I suspect this is a different style altogether that was already in the document before you attached the template. Word is finicky about capitalisation in style names and ‘Sub heading’ would be a different style to ‘Sub Heading’.

        ===================================================
        Upon further investigation I have discovered that my quoted method won’t work directly if the alias style already exists in the document that you are attaching the template to. If you paste the content into a document that already has the aliased style then it does work to merge styles. Also attaching the template and refreshing styles works to bring in the style if the alias style is not used already in the document.

    • #1221127

      To clear away the unwanted formatting, first, turn on keep track of formatting in Word options. Click the arrow to the right of Sub Heading 2, click “select all xx instances”, and then press Ctrl+[spacebar] to remove direct character formatting and Ctrl_q to remove direct paragraph formatting.

      Using the select all method usually applies the style without the keeping the formatting. On the rare occasions that it does not,use the clear the formatting icon on the home tab to clear all formatting of the selected text back to normal. Then apply the desired style.

      I prefer this method to find and replace.

    Viewing 3 reply threads
    Reply To: Heading styles Find and replace

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: