Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-15-2012, 07:27 AM
Ulodesk Ulodesk is offline Limiting a macro to a selection Windows 7 64bit Limiting a macro to a selection Office 2010 64bit
Word 2013 Expert Cert
Limiting a macro to a selection
 
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
 

Tags
limit macro



Similar Threads
Thread Thread Starter Forum Replies Last Post
Limiting a macro to a selection Selection is locked Thokkle Word 1 04-01-2012 06:46 PM
How do you add to a selection list? bryanarn Excel 2 03-05-2012 05:04 PM
Macro to populate a text form field based on dropdown selection koloa Word 0 10-20-2011 11:52 AM
Limiting the times that it runs hchbiker PowerPoint 0 02-09-2011 08:36 AM
Limiting a macro to a selection Save Selection cksm4 Word VBA 25 01-30-2011 11:44 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:34 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft