Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Recorded Macro Does Not Work As Expected (Word 2000)

    Using Word 2000, I recorded a macro with the following code to automate the
    process of removing extra spaces before paragraphs in some of my older
    documents. When I do the steps manually by center justifying and then left
    justifying the paragraphs all works well - the extra spaces disappear but
    when I try to run the code, nothing appears to change - extra spaces are
    still there. What is the difficulty here? Here is the code and thank you
    as always for your help.

    Selection.WholeStory
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft


    Gary Hunt

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Recorded Macro Does Not Work As Expected (Word 2000)


  3. #3
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Recorded Macro Does Not Work As Expected (Word 2000)

    Hi Gary,

    As Howard's article says, the macro recorder lies:
    Centering text from the user interface does not run
    <pre> Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter</pre>

    Instead, it calls the built-in command CenterPara.

    So you either have to use the built-in commands in your macro:
    <pre> Selection.WholeStory
    Application.Run "CenterPara"
    Application.Run "LeftPara"</pre>

    which is short and fast, but hard to understand if you don't know what the built-in Commands do.

    Or you'd have to write a "real" VBA program that removes the spaces, for example with two wildcard find/replaces:
    <pre> With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "(^13)^32{1;}"
    .Replacement.Text = "1"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
    .Text = "^32{1;}(^13)"
    .Execute Replace:=wdReplaceAll
    End With</pre>

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

  4. #4
    Star Lounger
    Join Date
    Jan 2001
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Recorded Macro Does Not Work As Expected (Word 2000)

    Thanks Lkaus for the insight and code. I will look more a how wildcards are used.

    Gary

Posting Permissions

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