1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Word Macro: how do I loop til end of file EOF

Discussion in 'Business Applications' started by TheSteelGeneral, May 8, 2012.

Thread Status:
Not open for further replies.
Advertisement
  1. TheSteelGeneral

    TheSteelGeneral Thread Starter

    Joined:
    Apr 8, 2009
    Messages:
    119
    Hi, I would like to perform the following macro till the end of the file, and I don't know the number of times it has to run.

    =========begin macro=========
    PHP:
        Selection.Find.ClearFormatting
        Selection
    .Find.Replacement.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:=wdCharacterCount:=1
        Selection
    .EndKey Unit:=wdLine
        Selection
    .TypeText Text:=" "
        
    Selection.Delete Unit:=wdCharacterCount:=1
        Selection
    .MoveRight Unit:=wdCharacterCount:=1
    End Sub
    ========end macro===========

    This is to replace the Returns with a Space in a word file that are in the middle of a sentence.
    Even if you know of a better way, I would still like to know how to repeat any macro till the end of file.
    I can't do a search and replace because ^$ is not a valid thing for the replace with box, which I get. I also don't know how set conditions in VBA. Thousand thanks!
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1052418