Re: Error 4609 string too long

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Roger Marrs (rmarrs_at_lvcoks.com)
Date: 03/24/04


Date: Wed, 24 Mar 2004 07:38:51 -0600

Hello Jay,

I tried shortening that, but I'm still getting the same "string too long"
error with the Selection.TypeText line being highlighted by the editor when
I click on debug.

When the macro is running, it seems like it is trying to insert the
INCLUDETEXT field over and over and over. I can see that line being
repeated multiple times on the screen before the macro locks up. The
document itself then contains only a single pair of { } at the first
instance of my highlighted text. Of course the macro is suppose to perform
the INCLUDETEXT function once at each instance of the highlighted text in
the document. I'm wondering if maybe the highlighted text isn't getting
replaced with the INCLUDETEXT field, which is then itself highlighted, and
then the marco just loops back onto itself until the highlighted text string
gets too long. How would I turn off the highlighting after the text has
been located in the document? It seems like that might fix the problem.
Thanks. Here's the snippet of code at issue:

Selection.Find.Highlight = True
With Selection.Find
    Do While .Execute(FindText:="", Wrap:=wdFindStop, Forward:=True) = True
        marker = Selection.Text
        Selection.Delete
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
        PreserveFormatting:=False
        Selection.TypeText Text:="INCLUDETEXT " & Chr(34) &
"I:\htltr\jdltr\prod\" & marker & ".doc" & Chr(34) & " B" & marker
        ActiveWindow.View.ShowFieldCodes = Not
ActiveWindow.View.ShowFieldCodes
        ActiveWindow.View.ShowFieldCodes = Not
ActiveWindow.View.ShowFieldCodes
    Loop
End With

Thanks for the assistance,
Roger

"Jay Freedman" <jay.freedman@verizon.net> wrote in message
news:eJRIBuQEEHA.2652@TK2MSFTNGP10.phx.gbl...
> Hi, Roger,
>
> This section of the code:
>
> > Selection.TypeText Text:="INCLUDETEXT " & Chr(34) &
> > "I:htltr\jdltr\prod\" & marker & ".doc" & Chr(34) & " B" & marker
> > ActiveWindow.View.ShowFieldCodes = Not
> > ActiveWindow.View.ShowFieldCodes
> > ActiveWindow.View.ShowFieldCodes = Not
> > ActiveWindow.View.ShowFieldCodes
>
> should be only three lines in the VBA editor. Put the cursor at the end of
> the "Selection.Type" line and press the Delete key, so the "I:..." stuff
> jumps back onto the same line. (By the way, are you missing a backslash
> after the colon in "I:htltr"?) Then go to the end of the Not, type a
space,
> and press Delete, and do the same to the other Not.
>
> I'm not 100% sure that will cure the problem, but if not you can come back
> again.
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
>
> Roger Marrs wrote:
> > A few months ago Doug Robbins was kind enough to help me out with
> > some code to search for highlighted text and replace it with
> > bookmarked text from another file. I had it working at one time, but
> > since then I changed computers, lost the macro and now I can't get it
> > to work.
> >
> > Here's the code:
> > Dim marker As String
> > Selection.HomeKey Unit:=wdStory
> > Selection.Find.ClearFormatting
> > Selection.Find.Highlight = True
> > With Selection.Find
> > Do While .Execute(FindText:="", Wrap:=wdFindStop, Forward:=True)
> > = True marker = Selection.Text
> > Selection.Delete
> > Selection.Fields.Add Range:=Selection.Range,
> > Type:=wdFieldEmpty, _ PreserveFormatting:=False
> > Selection.TypeText Text:="INCLUDETEXT " & Chr(34) &
> > "I:htltr\jdltr\prod\" & marker & ".doc" & Chr(34) & " B" & marker
> > ActiveWindow.View.ShowFieldCodes = Not
> > ActiveWindow.View.ShowFieldCodes
> > ActiveWindow.View.ShowFieldCodes = Not
> > ActiveWindow.View.ShowFieldCodes
> > Loop
> > End With
> >
> > When I try to run it, the Selection.TypeText Text:= line comes back
> > highlighted with the error 4609 "text string too long" message.
> > Also, the ActiveWindow.View.ShowFieldCodes = Not lines don't seem to
> > be accepted by the vba editor.
> >
> > Roger
>
>


Quantcast