none
Selection.Find.Execute Replace:=wdReplaceAll > works sometimes and sometimes NOT RRS feed

  • Question

  • Hello i have the string "fut contr exp" pasted inside some Word flowcharting objects and also just pasted in the regular Word text area and sometimes this VBA code will change the text in the FlowCharting object if i manually tweek the end character and sometimes it won't and the sometime it will change all of the regular Word text strings fine, but not the FlowCharting object, so it seems to be willy/nilly/hit/and/miss! Is there a setting in those find parameters i could set to make this a consistent utility?
    thanks very much for any ideas! bk

    Sub FindReplaceSentence2()
    Dim StrFnd As String
    Dim StrRep As String
    StrFnd = "fut contr exp"
    StrRep = "fut contr expr"
    Call FindRep(StrFnd, StrRep)
    End Sub

    Sub FindRep(StrFnd As String, StrRep As String)
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
       .Text = StrFnd
       .Replacement.Text = StrRep
       .Forward = True
       .Wrap = wdFindContinue
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    End Sub

    Sunday, July 10, 2011 9:33 PM

Answers

All replies

  • Word documents are arranged into what are called Stories and operations like this work on one story at a time. In this case it will be the story where the 'Selection' is, so if in your flowchart it will work there, if in the document body it will work there instead. See http://word.mvps.org/faqs/customization/ReplaceAnywhere.htm for how to run against all stories.
     
     

    Enjoy,
    Tony
    www.WordArticles.com
    • Marked as answer by bobk544 Tuesday, July 12, 2011 12:22 AM
    Monday, July 11, 2011 10:52 AM
  • Thanks very much Tony i think you are right about this and i'm going to test it tonight, this explanation really makes alot of sense and i can't wait to test it out!

    Ok will get back shortly!

    bk

    Monday, July 11, 2011 4:02 PM
  • Yes Tony that did it super! thanks again very much! you made my day, week!

    Have a great week also Tony and thanks for spending your valuable time helping me out with this conundrum!

    bk 

    Tuesday, July 12, 2011 12:25 AM