Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi

    The company has changed literature and the look of the documentation. Therefore, we need to change the content of existing documents (e.g. the indentation has been changed from -1 inch to .5 inch, the bullets/numbering has been again changed from -1 to .5, hanging indent has changed, etc). Mostly, the changes are indentation - left and hanging and for couple of styles from Arial to Verdana.

    Now, I have tried to create a macro that selects all and updatesstyles but this doesn't work! I thought ActiveDocument.UpdateStyles would update the styles of content of the document.
    I thought this would do the job:

    Sub UpdateAllStyles ()
    ActiveDocument.Range.Select
    ActiveDocument.UpdateStyles
    End Sub

    Do I need to go through the document selecting each para and updating the styles for it?

    Edit: I guess the other question is, how can I select say all para's with Heading 1 style? I know I can (once all paras with same style are selected) then do the following: Selection.Style = ActiveDocument.Styles("Heading 1"). This would reset all indentation etc.
    Thanks.
    Robie

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    There should be no need to select anything. Just ActiveDocument.UpdateStyles is enough to update the styles in the document with those in the template.

    But updating the styles will not overrule directly applied formatting. So if a style has been set to use Arial, but a paragraph with that style has been formatted with Times New Roman, updating the styles will leave that paragraph set to Times New Roman. This also holds if the paragraph has explicitly been set to Arial, even if the style already specified Arial. After updating the styles will leave the paragraph set to Arial, because that font was applied as direct formatting.

    You can, of course, reset the character and paragraph formatting after updating the styles:

    Code:
    With ActiveDocument.Content
      .ParagraphFormat.Reset
      .Font.Reset
    End With
    but that will remove ALL directly applied formatting!

  3. #3
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='780048' date='16-Jun-2009 13:16']There should be no need to select anything. Just ActiveDocument.UpdateStyles is enough to update the styles in the document with those in the template.

    But updating the styles will not overrule directly applied formatting. So if a style has been set to use Arial, but a paragraph with that style has been formatted with Times New Roman, updating the styles will leave that paragraph set to Times New Roman. This also holds if the paragraph has explicitly been set to Arial, even if the style already specified Arial. After updating the styles will leave the paragraph set to Arial, because that font was applied as direct formatting.

    You can, of course, reset the character and paragraph formatting after updating the styles:

    Code:
    With ActiveDocument.Content
      .ParagraphFormat.Reset
      .Font.Reset
    End With
    but that will remove ALL directly applied formatting![/quote]

    That's exactly what I thought as well but it doesn't! The styles applied to the original document are by selecting the style from the list of styles & no inline modifications to them at all. If I put my cursor on a para with Heading 2 and then select 'Heading 2" style it resets the whole paragraph correctly (as in attachment). I thought ActiveDocument.UpdateStyles would do this for the whole of the document.
    Attached Images Attached Images
    Thanks.
    Robie

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    [quote name='robie' post='780050' date='16-Jun-2009 14:34']I thought ActiveDocument.UpdateStyles would do this for the whole of the document.[/quote]
    It does when i try it (I've tested it several times now, with various heading and non-heading styles). The fact that the style *is* applied correctly when you select it makes me suspect that - despite your assurance - direct formatting has been applied. Otherwise I can't explain the behavior that you describe.

  5. #5
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Your description of the problem doesn't mention 'template' anywhere.
    The ActiveDocument.UpdateStyles code re-imports the style definitions from the attached template so the template that is attached to the document is all important. Have you checked the attached template to verify that the new styles are correctly defined. This can be a bit tricky because if the template name exists in multiple locations (user templates, workgroup templates, attached template path, same folder as docs) then Word may be using an alternate location for the template.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

Posting Permissions

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