excel vba - VBA Word: conditional text replacement -


i have macro searches replaces series of words in document code:

'define array1 words want replaced 'define array2 words want replace have same index 'loop through array , search , replace application.activedocument.content.find i=1 565 .text=array1(i) .replacement.text=array2(i) .wrap=wdfindcontinue .format=false .matchcase=false .matchwholeword=true .matchwildcards=false .matchallwordsforms=false .matchsoundslike=false .matchsuffix=true .matchprefix=true .execute replace:=wdreplaceall next end 

i want change functionality won't replace word if first word in line, realize find function doesn't work line line, or allow conditional testing of properties, think best approach me change range function operates on exclude first word in each line.

so instead of activedocument.content.find need activedocument.range defined somehow excludes first word of each line.

does know how define range excludes first word of each line.

thanks

not sure of application , "first word in line" assume meant first word of paragraph, works apply search entire paragraph (except first word)

'array position 0    1    2    3    4 array1 = array("1", "2", "3", "4", "5") array2 = array("one", "two", "three", "four", "five")  p = 1 activedocument.paragraphs.count    'seelcting paragraph    activedocument.paragraphs(p).range.select    'checking if paragraph not blank line     if len(selection) > 1         'moving begining of paragraph         selection.homekey         'moving 1 word left         selection.moveright unit:=wdword, count:=1         'selecting rest of paragraph         selection.moveend unit:=wdparagraph         'setting selection bookmark         activedocument.bookmarks.add range:=selection.range, name:="tempbm"          = 0 4             selection.find                 .text = array1(i)                 .replacement.text = array2(i)                 .forward = true                 .wrap = wdfindstop                 .format = false                          'replace text                 while .execute(replace:=wdreplaceone)                   'reselect bookmark                   selection.goto what:=wdgotobookmark, name:="tempbm"                 loop              end         next         'deleting bookmark         activedocument.bookmarks("tempbm").delete     end if next 

for test change (i added 1 first word verify ignores it:

1this test 1 2 3 4 5

1this test 1 2 3 4 5

to:

1this test 1 2 3 4 5

1this test 1 2 3 4 5


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

mysql - FireDac error 314 - but DLLs are in program directory -