• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1072
  • Last Modified:

Word.Range.Find.Execute Replace String too Long

Hi,
I am doing the following

            'A very long string length ~ 700
            strResponse = "abc................................."
            rngTemplate.Find.Text = "<<Text>>"
            rngTemplate.Find.Replacement.Text = strResponse
            rngTemplate.Find.Execute Replace:=wdReplaceOne
           
I get an error when i assign the template, the strResponse Text...The reason beign that its too long. The strResponse in my prgm will always be very long. Please help on how to insert a long string into a template at a specific position.

Thank you!
0
jainpriyanka
Asked:
jainpriyanka
  • 2
1 Solution
 
NBrownohCommented:
break the string down to acceptable lengths and use a for loop do input the string instead of trying to do it all at once.

kind like this

Do While len(VeryLongString) > 0
            if len(VeryLongString) >  251 then
                   strResponse = mid(VeryLongString, 1, 250) & "<<Text>>"
                   VeryLongString = mid(VeryLongString, 251)
            else
                   strResponse = VeryLongString
            end if
            rngTemplate.Find.Text = "<<Text>>"
            rngTemplate.Find.Replacement.Text = strResponse
            rngTemplate.Find.Execute Replace:=wdReplaceOne
loop
0
 
_agj_Commented:
what about

            set wrd = rngTemplate.Find( "<<Text>>")
            wrd.replace strResponse

           or

          set wrd = rngTemplate.Find( "<<Text>>")
          wrd(1) = strResponse.
0
 
NBrownohCommented:
crap man, i hate putting errors in my code, seems to be happening a lot lately, probably should get to bed sooner :)

after the else, if you have a string that is less than 251 characters that code will never end, so put this line in before then end if
VeryLongString = ""

and, glad i could help you out.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now