Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    East Tennessee
    Posts
    179
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Macro to repeat to end of Selection (Word)

    I want to construct a macro that will repeat until it reaches the end of a selection.

    It seem that should work with a do..loop, but I can't find the key to finding the end of the set of lines that I select. I have the macro that will perform the operations that I want.
    Win 8, Firefox 16.0.2, Thunderbird 15.0.2

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

    Re: Macro to repeat to end of Selection (Word)

    Please provide some details about what the macro is supposed to do.

  3. #3
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    East Tennessee
    Posts
    179
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Macro to repeat to end of Selection (Word)

    Thanks for your rapid response!

    What I want to do is search for a character ([img]/forums/images/smilies/smile.gif[/img] and then delete from that character to the begining of the line (paragraph). Because I want to do that delete, I don't think I can just use the search feature by itself. The way I had constructed the macro was to
    1. find,
    2. then select to start of line,
    3. delete,
    4. move down a line
    5. repeat the process.
    That works fine manually repeating line by line, but I would like it to do the selected lines.

    Here is the macro I recorded
    Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 7/10/2005
    '
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = ":"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindAsk
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.Delete Unit:=wdCharacter, Count:=1

    End Sub
    Win 8, Firefox 16.0.2, Thunderbird 15.0.2

  4. #4
    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: Macro to repeat to end of Selection (Word)

    The following simple code may do what you want, but note that it will miss the first line in the Selection unless the Selection includes the paragraph mark that precedes that first line (and will unavoidably miss the first line if the first line isn't preceded by a paragraph mark -- e.g., is at the very start of the document).

    If you need to also process the first line even if it isn't preceded by a paragraph mark, post back and hopefully one of the Find/Replace gurus can offer you a more complex solution.
    <pre> With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^13*:"
    .Replacement.Text = "^p"
    .Format = False
    .Forward = True
    .Wrap = wdFindStop
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = True
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll
    End With</pre>


  5. #5
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    East Tennessee
    Posts
    179
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Macro to repeat to end of Selection (Word)

    Thanks again, you got me very close!

    What I did was add the lines below to; move to top, add a blank line, move up, and run your sugestion.

    Selection.HomeKey Unit:=wdStory
    Selection.TypeParagraph
    Selection.MoveUp Unit:=wdLine, Count:=1
    Win 8, Firefox 16.0.2, Thunderbird 15.0.2

Posting Permissions

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