Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Word.Range.Find.Execute Replace String too Long

Posted on 2003-11-04
3
900 Views
Last Modified: 2012-08-13
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
Comment
Question by:jainpriyanka
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
NBrownoh earned 125 total points
ID: 9682236
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
 
LVL 7

Expert Comment

by:_agj_
ID: 9684372
what about

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

           or

          set wrd = rngTemplate.Find( "<<Text>>")
          wrd(1) = strResponse.
0
 
LVL 3

Expert Comment

by:NBrownoh
ID: 9688299
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question