Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Stop attached code changing the format of text (2000 / 2003)

    Hi,

    Attached is some code I use to change the font and size of a document. It also changes the style i.e BOLD, ITALIC, UNDERLINE etc

    I only want it to change the FONT and SIZE to Arial, 11

    Any ideas

    Thanks
    Attached Files Attached Files
    Regards
    Gerbil (AKA Kevin)

  2. #2
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Stop attached code changing the format of text (2000 / 2003)

    What happens if you cut your macro down to just the following 4 lines?
    <pre> With ActiveDocument.Styles(wdStyleNormal).Font
    .Name = "Arial"
    .Size = 11
    End With</pre>

    If the paragraphs are already Normal style (or a style based on Normal, without separate font settings), that should do it. If you're changing the styles of paragraphs, things get more complicated. For example, any time you apply a paragraph style to an existing paragraph, any manual formatting (including bold or italic) that applies to more than 50% of the paragraph and isn't consistent with the paragraph style will be eliminated. This will happen even if you're just "re-applying" the Normal style to a paragraph that was already Normal style.

    Also: your macro includes a .Font.Reset line, and I think that will eliminate manual formatting regardless of what the rest of the macro does or doesn't do.

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Stop attached code changing the format of text (2000 / 2003)

    The code you posted is very complex for such a simple aim but it will catch ranges that a simpler model doesn't - eg header/footer/text boxes. I don't see the need to blow away the paragraph styles as part of this macro and this is part of the reason you are losing other formatting attributes. The other reason is the rngStory.Font.Reset line.

    I would tend to want to retain the paragraph styles in case I changed my mind later and wanted to get back to the original style settings. So my simple version is along the lines of
    <pre> With ActiveDocument.Range.Font
    .Name = "Arial"
    .Size = 11
    End With</pre>

    You could apply the same principle to your more complex code if you wanted to catch those other possible storyranges.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Stop attached code changing the format of text (2000 / 2003)

    Thank you to both of you.

    Removing rngStory.Font.Reset worked, however I have also noticed the any right/centered justification is also lost.

    Any ideas how to leave that inplace or better still to ignore any text within a table would be better.

    Many thanks
    Regards
    Gerbil (AKA Kevin)

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Stop attached code changing the format of text (2000 / 2003)

    The line

    rngStory.ParagraphFormat.Reset

    resets the paragraph format (such as justification), so you should remove that line too.

  6. #6
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Stop attached code changing the format of text (2000 / 2003)

    Thank you,

    Learning somthing everyday here! Many thanks to you all
    Regards
    Gerbil (AKA Kevin)

Posting Permissions

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