Consulting

Results 1 to 6 of 6

Thread: Troubleshoot code please?

  1. #1

    Troubleshoot code please?

    Hey everyone,
    I'm hoping someone can help me out with this please ?

    I'm trying to set up a macro to :
    remove double spacing between words
    remove double paragraph spacing
    change body text font to garamond 12pt

    I'm using the macro recorder and find / replace to do it.

    I can get it to work for the first 2 action but it's not changing the font.
    Can you take a look at the code and see if there's any way to tweek it ?

    Thanks.
    Attached Images Attached Images

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Hi Blaze,

    First off, when posting code, please post the code - not an image of it. And, when doing, so, please use the VBA tags.

    Rather than trying to hard-format the text in 12pt Garamond, you should define a Style with those attributes and apply the Style. The following code should achieve what you're after:
    [VBA]Sub Reformat()
    Application.ScreenUpdating = False
    With ActiveDocument.Content.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    'Clean up double spacing
    .Execute Replace:=wdReplaceAll
    .Text = "[ ]{2,}"
    .Replacement.Text = " "
    'Clean up multiple paragraph breaks
    .Execute Replace:=wdReplaceAll
    .Text = "[^13]{2,}"
    .Replacement.Text = "^p"
    'Validate all paragraph breaks and apply the required Style
    .Execute Replace:=wdReplaceAll
    .Text = " ^13"
    .Replacement.Style = "SomeStyle"
    .Execute Replace:=wdReplaceAll
    End With
    Application.ScreenUpdating = True
    End Sub[/VBA]
    You will, of course, need to rename 'SomeStyle' to whatever your 12pt Garamond Style is. And, if you want the Find/Replace to work on a specific selection, change 'ActiveDocument.Content.Find' to 'Selection.Find'.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Nice, clean, well articulated response.

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Cross-posted at: http://www.msofficeforums.com/vba/12...-font-vba.html
    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    Sorry Paul,
    That's what lack of sleep will get you, I thought I'd joined 2 different forums.

    Thank you so much for the response, I really appreciate you taking the time to put that together for me.

    Now I just have to sit down with it and work out what it all means.

    Thanks again.

  6. #6
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Quote Originally Posted by blaze2012
    I thought I'd joined 2 different forums.
    That is indeed what you did. There is no objection to cross-posting per se. However, you posted essentially the same question in both forums, without giving any indication in either of them that's what you'd done.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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