Solved

Word.Range.Find.Execute Replace String too Long

Posted on 2003-11-04
3
856 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now