VBA in MS Word affects whole document, not just selection -


i want have vba script perform find / replace in selection , assign macro button on quick access toolbar, save having click through usual find/replace procedure.

i recorded macro while doing , get:

 sub findreplace()       '       ' findreplace macro       '       '      selection.find.clearformatting      selection.find.replacement.clearformatting      selection.find          .text = "^p"          .replacement.text = " "          .forward = true          .wrap = wdfindask          .format = false          .matchcase = false          .matchwholeword = false          .matchwildcards = false          .matchsoundslike = false          .matchallwordforms = false      end      selection.find.execute replace:=wdreplaceall  end sub 

but when run macro on selection change paragraph marks spaces continues on change whole document, not selection.

i'm no stranger vba can't see how fix stops when selection done.

you going need use

     .wrap = wdfindstop 

instead of

     .wrap = wdfindask 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -