Solved

Word.Range.Find.Execute Replace String too Long

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

929 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

11 Experts available now in Live!

Get 1:1 Help Now