Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Dec 2001
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    looping macro to doc end (Word 2000 SR1)

    I have a macro that I recorded to do a chore (I've never learned to write macros). But I don't know how to loop it to the end of the document. Can someone help me with the language needed? I would certainly appreciate it.

    Nancy Potter

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: looping macro to doc end (Word 2000 SR1)

    The method for making the macro work across the whole document depends on exactly what it is doing.
    Can you post the macro so far, so that we can see what it doesl, if it is long then attach it as a text file.

    StuartR

  3. #3
    Lounger
    Join Date
    Dec 2001
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: looping macro to doc end (Word 2000 SR1)

    Macro was constructed to replace returns in a damaged document (300 pgs, approx 6000 paras, some only one line; doc is auto numbered with auto captions and cross refs).

    Document is damaged. Since damage usually resides in para returns, I wanted to try to replace the 2 characters right before each return by doing a copy/paste of those characters right in front of the originals, then typing a new return, then deleting the original 2 characters and the old return. Knew I couldn't just replace returns with new ones.

    I've tried saving off document as HTML to fix it, but haven't been successful. I needed to do comparison of the new version and an older version. I broke up docs into sections to do the comparison and most of my tries crashed, even after I saved off both versions as HTML then resaved as Word docs. This document is going to be around a long time and will be revised many times. I need to fix it now and I hope I don't need to take it out to text and then bring it all back to do that.

    Hope you can help me finish off the macro.

    Nancy

    ' damage Macro
    ' Keystroke = Alt Shift ) Replace para returns in damaged doc by copy/paste of last 2 char before return, new return, then delete original 2 char & orig return.
    '
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = "^p"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.MoveLeft Unit:=wdCharacter, Count:=2, Extend:=wdExtend
    Selection.Copy
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.Paste
    Selection.TypeParagraph
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    End Sub

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: looping macro to doc end (Word 2000 SR1)

    I don't really understand what you are doing, but this macro does what you asked for <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    The bit you asked for is in...
    While .Execute And Selection.End <> ActiveDocument.Content.End
    <font color=448800>' put your code here </font color=448800>
    Wend

    This repeats the Selection.Find.Execute until we get to the end of the document or fail to get a match.

    StuartR


    Public Sub SRTest()
    With Selection.Find
    .ClearFormatting
    .Text = "^p"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    While .Execute And Selection.End <> ActiveDocument.Content.End
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.MoveLeft Unit:=wdCharacter, Count:=2, Extend:=wdExtend
    Selection.Copy
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.Paste
    Selection.TypeParagraph
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Delete Unit:=wdCharacter, Count:=1
    Wend
    End With
    End Sub

  5. #5
    Lounger
    Join Date
    Dec 2001
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: looping macro to doc end (Word 2000 SR1)

    I never thanked you for your help. My macro zipped right thru to the end of the doc. I would have spent hours doing what that macro did in only a couple of minutes.

    Nancy Potter

Posting Permissions

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