View Single Post
 
Old 06-15-2012, 07:27 AM
Ulodesk Ulodesk is offline Windows 7 64bit Office 2010 64bit
Word 2013 Expert Cert
 
Join Date: Sep 2009
Location: Virginia
Posts: 872
Ulodesk is on a distinguished road
Default Limiting a macro to a selection

I cannot determine what command is needed to restrict the following macro, created using the macro recorder, to my selection. I have looked through all my other macros and can't figure out what allows some of them to operate this way. One them works one the whole document if I select nothing, or works on a selection, but why is beyond me, except that it's useful. I have tried to use the recorder to isolate this aspect, to no avail.
Thanks in advance!


Code:
Sub ParasStripSelected()
'
' ParasStripSelected Macro
'
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^p"
        .Replacement.Text = " "
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
End Sub
I suspect that al those = False lines could be deleted, but I'll wait to have a working macro to try that out.

Last edited by Ulodesk; 06-15-2012 at 07:29 AM. Reason: Added a note.
Reply With Quote