Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Jun 2001
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macros (Word 2002)

    <P ID="edit" class=small>(Edited by jscher2000 on 14-Dec-03 12:07. Inserted [pre] and [/pre] markup around the code excerpt to preserve indenting.)</P>I have created this macro with the help of someone in this forum.

    <pre>Sub SelectToDblePara()
    Selection.Extend
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = "^p^p"
    .Forward = True
    End With
    Selection.Find.Execute
    Selection.Document.Kind = wdDocumentNotSpecified
    Selection.Range.AutoFormat
    Selection.MoveDown Unit:=wdLine, Count:=1
    End Sub</pre>


    My problem is that the macro does not 'DEhighlight' the text. I have to press the right arrow key for it to dehight the text. What am I doing wrong? Can anyone help me.

    Thank you.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Macros (Word 2002)

    The MoveUp/MoveDown/MoveLeft/MoveRight methods usually will collapse the selection in that direction. However, at the beginning of your macro you turned on Extend Mode, which changes that behavior. So try this: just before this line --

    Selection.MoveDown Unit:=wdLine, Count:=1

    -- turn off the Extend mode --

    Selection.ExtendMode = False

    One other note: using wdLine sometimes will cause your insertion point to be placed in an unexpected position. Generally you will get more predictable results if you use:

    Selection.MoveDown Unit:=wdParagraph, Count:=1

    So, your code could read as follows:

    <pre>Sub SelectToDblePara()
    With Selection
    .ExtendMode = True
    With .Find
    .ClearFormatting
    .Text = "^p^p"
    .Forward = True
    If .Execute = False Then Exit Sub
    End With
    .Document.Kind = wdDocumentNotSpecified
    .Range.AutoFormat
    .ExtendMode = False
    .MoveDown Unit:=wdParagraph, Count:=1
    End With
    End Sub</pre>

    I used another set of With/End With pairs, and I added an Exit Sub if the search fails (e.g., end of document). Hope this helps.

  3. #3
    2 Star Lounger
    Join Date
    Jun 2001
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macros (Word 2002)

    Thank you so very much for your help. It works like a charm.

    Maria

Posting Permissions

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