String too long...

M

mike

Hello,

This example works for Selection.TypeText seems to work well even after a .Find & .Execute

http://support.microsoft.com/kb/181110

I am maintaing an application and am a bit new working with Word Objects.

I am in another section of code and am not been able to obtain the benefit of Selection.TypeText the code happens to be working with the Range object.

How might one go about implementing this if working with a Range.Find & Execute?

- Mike
 
J

Jezebel

Perhaps you could get someone to translate your question into English for
you, and post it again.


Hello,

This example works for Selection.TypeText seems to work well even after a
..Find & .Execute

http://support.microsoft.com/kb/181110

I am maintaing an application and am a bit new working with Word Objects.

I am in another section of code and am not been able to obtain the benefit
of Selection.TypeText the code happens to be working with the Range object.

How might one go about implementing this if working with a Range.Find &
Execute?

- Mike
 
M

mike

Awfully sorry, it had been a terribly long week, with lot's of time pressures. I wasn't able to proof-read the note and on second look it surely needed it. I'll Try again...

I am maintaining an application and am a bit new working with Word Objects.

The Microsoft example in the link provided below seems to work well as a solution for one particular section of the application that I am working on. I have implemented Selection.TypeText immediately after performing Selection.Find & .Execute, as an alternative to their Selection.GoTo bookmark example.

http://support.microsoft.com/kb/181110

I am now in another section of the code that I am maintaining and am not able to obtain the safety benefits of Selection.TypeText. That is this particular section of code happens to be working with the Range object, however I would like to apply the TypeText solution.

How might one go about implementing this Microsoft example, if working with the results of a Range.Find & Execute?

Something to the affect of...

If Range.Find then
Selection.Idunno = Range.Idunno
Selection.TypeText (String((256, "W"))
End If

- Mike
 
T

Tony Jollans

The KB article you refer to relates to FormFields but you don't say you are
working with FormFields so I'm not entirely sure what you want but the
equivalent of TypeText is simply ..

(range).Text = "this is what I want there"

--
Enjoy,
Tony

Awfully sorry, it had been a terribly long week, with lot's of time
pressures. I wasn't able to proof-read the note and on second look it surely
needed it. I'll Try again...

I am maintaining an application and am a bit new working with Word Objects.

The Microsoft example in the link provided below seems to work well as a
solution for one particular section of the application that I am working on.
I have implemented Selection.TypeText immediately after performing
Selection.Find & .Execute, as an alternative to their Selection.GoTo
bookmark example.

http://support.microsoft.com/kb/181110

I am now in another section of the code that I am maintaining and am not
able to obtain the safety benefits of Selection.TypeText. That is this
particular section of code happens to be working with the Range object,
however I would like to apply the TypeText solution.

How might one go about implementing this Microsoft example, if working with
the results of a Range.Find & Execute?

Something to the affect of...

If Range.Find then
Selection.Idunno = Range.Idunno
Selection.TypeText (String((256, "W"))
End If

- Mike
 
M

mike

Yes I understand that, thanks Tony.

Now if we wanted to make your code use a variable safely, then next step might be...

Dim myString As String
myString = "this is what I want there"

If Len(myString) < 255 Then
(range).Text = myString
End If

If we want to expand on your example further, you might say we arrive at my question... How do we do the the Else?


If Not Len(myString) < 255 Then
(range).Text = myString
Else
Selection.Idunno = (range).Idunno
Selection.TypeText myString
End If

Thanks again, - Mike
 
T

Tony Jollans

All you need to do is:

(range).Select

But why do you want to use the Selection?

--
Enjoy,
Tony

Yes I understand that, thanks Tony.

Now if we wanted to make your code use a variable safely, then next step
might be...

Dim myString As String
myString = "this is what I want there"

If Len(myString) < 255 Then
(range).Text = myString
End If

If we want to expand on your example further, you might say we arrive at my
question... How do we do the the Else?


If Not Len(myString) < 255 Then
(range).Text = myString
Else
Selection.Idunno = (range).Idunno
Selection.TypeText myString
End If

Thanks again, - Mike
 
M

mike

That doesn't appear to be the ticket but Thank you Tony.

It is harder to articulate the question!
But why do you want to use the Selection?

The objective is to go beyond the 255 character limitation of (range).Text.
The same problem applies to (selection).Text

The recommended solution is in the MS KB article. I believe they're not
saying you must use Form Fields. I believe the gist is that they're saying
Selection.TypeText will accept and utilize an already allocated buffer. As
opposed to copying a string into the .Text buffer that can only accept 255
characters.

Using the Range object try to Find a Tag <myTag> and then replace the tag
with a long string myLongString.
 
T

Tony Jollans

There is not a general 255-character limit; it is only in certain
circumstances. The KB article you refer to is saying that there is a
255-character limit putting text in formfields and shows one way to get
round it. If you're not using Form Fields to start with, the article does
not apply to you.

What exactly are you finding does not work? Can you post actual code?
 
M

mike

Hi Greg,

I brought your example as a potential approach, while it works great, the
boss wants to use the Microsoft recommended approach instead of copying the
long string to the ClipBoard.

All that I am looking to do is Replace some text (a tag) with a long string.
It is the same premise as your example.

The question is how might one implement Selection.TypeText when the text
(tag) is found with the Range object?

Has anyone tried this? It is not Form Field specific. I say that because it
works great with Selection.Find, however there is an area in this program
that uses Range.Find.

The behavior that I observe is that when the Range object finds the text
tag, lets say it is the 3rd bookmark, half way through the document. An
execution of Selection.TypeText myLongString will write out the long string
at the top of the document.
 
G

Greg Maxey

I wouldn't think one would want to implement slection.typetext when
working with a range. Seems one would use range.text = whatever the
string is.

Is something like this what you are looking for:

im oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "<mytag>"
While .Execute
oRng.Text = "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "and on and on and on"
oRng.Collapse wdCollapseEnd
Wend
End With
End Sub
 
M

mike

This is where I had success...

MY.SYMPTONS
Dim sData As String

Dim sDataInsertionTag As String

sData = String(256, "x")

sDataInsertionTag = "<Additional_Info>"



' Setup Find

Set oFindObject = objWord.Selection.Find

With oFindObject

.ClearFormatting

.Text = sDataInsertionTag



' Setup Replacement

With .Replacement

.Text = sData ' Run-time error 5854 "String parameter is too long"

End With



.Execute Replace:=wdReplaceOne, MatchCase:=True, Forward:=True



End With

Set oFindObject = Nothing


MY.WORKAROUND
Dim sData As String

Dim sDataInsertionTag As String

sData = String(256, "x")

sDataInsertionTag = "<Additional_Info>"



' Setup Find

Set oFindObject = objWord.Selection.Find

With oFindObject

.ClearFormatting

.Text = sDataInsertionTag



' Setup Replacement

If .Execute(MatchCase:=True, Forward:=True) Then

objWord.Selection.TypeText sData

End If



End With

Set oFindObject = Nothing
 
M

mike

This is where I am having a problem

MY.SYMPTONS
Dim sData As String

Dim sDataInsertionTag As String

sData = String(256, "x")

sDataInsertionTag = "<Additional_Info>"



' Setup Find

Set oFindObject = objWord.Selection.Range.Find

With oFindObject

.ClearFormatting

.Text = sDataInsertionTag



' Setup Replacement

With .Replacement

.Text = sData ' Run-time error 5854 "String parameter is
too long"

End With



.Execute Replace:=wdReplaceOne, MatchCase:=True, Forward:=True



End With

Set oFindObject = Nothing


MY.NEEDED.WORKAROUND
Dim sData As String

Dim sDataInsertionTag As String

sData = String(256, "x")

sDataInsertionTag = "<Additional_Info>"



' Setup Find

Set oFindObject = objWord.Selection.Range.Find

With oFindObject

.ClearFormatting

.Text = sDataInsertionTag



' Setup Replacement

If .Execute(MatchCase:=True, Forward:=True) Then

objWord.Selection.Select ' Ineffective

objWord.Selection.Range.Select ' Ineffective as well

objWord.Selection.TypeText sData

End If



End With

Set oFindObject = Nothing
 
G

Greg Maxey

With the exception of your use of the string funciton which I didn't
think of, your work around solutions looks very similiar to my last
post:

Sub Test1()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "<Additional_Info>"
While .Execute
oRng.Text = String(256, "1")
oRng.Collapse wdCollapseEnd
Wend
End With
End Sub

Why do you want to to use Selection instead of range?
 
M

mike

I am beginning to wonder, is it maybe a version thing?



I have to support Word 2000 and perhaps that is why my environment errors when placing 256 characters into Range.Text



I am guessing that the code below is you stating that it is OK to exceed 255 characters? If so I am confused as to why you would demonstrate that while your web page shows how to alleviate the error?



At any rate, what might your apprehensions be with using Selection.TypeText after having found with the Range object, is there an issue of some sort that I should be aware of?



I have been thinking that, similar to a cursor, we'd simply move it to where the Range.Find is now pointing and TypeText into the location.
 
G

Greg Maxey

Mike,

My website mainly addresses the limitation of "finding" text that is longer
than "255" characters. Your find text <Additional_Items> is not the
problem.

The "replace" text limitation is easily overcome using the contents of the
clipboard or an autotext (Replace All) works in both cases.

Neither method you have found or that I proposed invokes "Replace All" and
so while it appears to the observer to be a find and replace operation it is
actually more of a "find and then change what is found" ;-)

I don't think there is anything wrong with using the selection.typetext
method. I have just gathered from nosing around in these groups that range
seems to be preferred over selection when possible. I believe it may be a
little quicker, but for most jobs the advantage may be negliable.




--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

I am beginning to wonder, is it maybe a version thing?



I have to support Word 2000 and perhaps that is why my environment errors
when placing 256 characters into Range.Text



I am guessing that the code below is you stating that it is OK to exceed
255 characters? If so I am confused as to why you would demonstrate that
while your web page shows how to alleviate the error?



At any rate, what might your apprehensions be with using
Selection.TypeText after having found with the Range object, is there an
issue of some sort that I should be aware of?



I have been thinking that, similar to a cursor, we'd simply move it to
where the Range.Find is now pointing and TypeText into the location.



Greg Maxey said:
I wouldn't think one would want to implement slection.typetext when
working with a range. Seems one would use range.text = whatever the
string is.

Is something like this what you are looking for:

im oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "<mytag>"
While .Execute
oRng.Text = "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "1111111111111111111111111111111111111111111111111" _
& "and on and on and on"
oRng.Collapse wdCollapseEnd
Wend
End With
End Sub
help:- Hide quoted text -- Show quoted text -
 
M

mike

Iv'e not really heard of the AutoText except in the searches for the dreaded run-time error 5854.

Oh yeah I did try on Word 2003 and still reproduce the error.

In my case I don't need Replace all, there is a preliminary run-through of the document that occurs. It is preparation for the database queries, and then afterwords the replace is within an overall ForEach loop.

So, you know what, we still haven't figured out how to position the Selection to the Range's found text!
Mike,

My website mainly addresses the limitation of "finding" text that is longer than "255" characters. Your find text <Additional_Items> is not the problem.

The "replace" text limitation is easily overcome using the contents of the clipboard or an autotext (Replace All) works in both cases.

Neither method you have found or that I proposed invokes "Replace All" and so while it appears to the observer to be a find and replace operation it is actually more of a "find and then change what is found" ;-)

I don't think there is anything wrong with using the selection.typetext method. I have just gathered from nosing around in these groups that range seems to be preferred over selection when possible. I believe it may be a little quicker, but for most jobs the advantage may be negliable.




--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

I am beginning to wonder, is it maybe a version thing?



I have to support Word 2000 and perhaps that is why my environment errors when placing 256 characters into Range.Text



I am guessing that the code below is you stating that it is OK to exceed 255 characters? If so I am confused as to why you would demonstrate that while your web page shows how to alleviate the error?



At any rate, what might your apprehensions be with using Selection.TypeText after having found with the Range object, is there an issue of some sort that I should be aware of?



I have been thinking that, similar to a cursor, we'd simply move it to where the Range.Find is now pointing and TypeText into the location.
 
T

Tony Jollans

Oh yeah I did try on Word 2003 and still reproduce the error.

What error exactly (I know, string too long!) and under what circumstances?
Please post code that is failing and indicate where.
So, you know what, we still haven't figured out how to position the
Selection to the Range's found text!

First of all, when you said in an earlier post that it's not the ticket what
is your problem with RangeObject.Select? Are you saying it does not select
the Range?

Secondly, I'll ask again, why are you so intent on using the Selection? Greg
has demonstrated how to use a Range. There are two (related) issues with
using the selection - it reflects what you are doing on screen in full view
of the user and this can be annoying because the screen can flicker and also
it is inefficient.

--
Enjoy,
Tony

Iv'e not really heard of the AutoText except in the searches for the dreaded
run-time error 5854.

Oh yeah I did try on Word 2003 and still reproduce the error.

In my case I don't need Replace all, there is a preliminary run-through of
the document that occurs. It is preparation for the database queries, and
then afterwords the replace is within an overall ForEach loop.

So, you know what, we still haven't figured out how to position the
Selection to the Range's found text!
Mike,

My website mainly addresses the limitation of "finding" text that is longer
than "255" characters. Your find text <Additional_Items> is not the
problem.

The "replace" text limitation is easily overcome using the contents of the
clipboard or an autotext (Replace All) works in both cases.

Neither method you have found or that I proposed invokes "Replace All" and
so while it appears to the observer to be a find and replace operation it is
actually more of a "find and then change what is found" ;-)

I don't think there is anything wrong with using the selection.typetext
method. I have just gathered from nosing around in these groups that range
seems to be preferred over selection when possible. I believe it may be a
little quicker, but for most jobs the advantage may be negliable.




--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

I am beginning to wonder, is it maybe a version thing?

I have to support Word 2000 and perhaps that is why my environment errors
when placing 256 characters into Range.Text

I am guessing that the code below is you stating that it is OK to exceed 255
characters? If so I am confused as to why you would demonstrate that while
your web page shows how to alleviate the error?

At any rate, what might your apprehensions be with using Selection.TypeText
after having found with the Range object, is there an issue of some sort
that I should be aware of?

I have been thinking that, similar to a cursor, we'd simply move it to where
the Range.Find is now pointing and TypeText into the location.
 
M

mike

Hi Tony, thanks for your interest,
Please post code that is failing and indicate where.
There is not a general 255-character limit; it is only in certain
circumstances. The KB article you refer to is saying that there is a
255-character limit putting text in formfields and shows one way to get
round it. If you're not using Form Fields to start with, the article does
not apply to you.
What exactly are you finding does not work? Can you post actual code?

There is a reply with two separate posts to your message with sample code (formatted similar to a Microsoft KB) I am not sure if you don't see them for some reason. If your News Reader goes directly to microsoft.public.word.vba.general you should.
First of all, when you said in an earlier post that it's not the ticket what
is your problem with RangeObject.Select? Are you saying it does not select
the Range?

Yes, see my sample code that was sent replying to you. In the second posting, the one that implements Range.Find has two lines that have "ineffective" commented beside them.
Secondly, I'll ask again, why are you so intent on using the Selection? Greg
has demonstrated how to use a Range. There are two (related) issues with
using the selection - it reflects what you are doing on screen in full view
of the user and this can be annoying because the screen can flicker and also
it is inefficient.


I didn't really wake up one day saying that "I need to use Selection." We're experiencing Run-time error '5854' "String parameter is too long" when placing long text into both Selection.Find.Replacement.Text and Range.Find.Replacement.Text. So I began an investigation.

One stop, of many, was at a MS KB article recommeding Selection, because it offers TypeText. I found this solution "also" works splended after a Selection.Find, see the first sample code posting that employs Selection.Find.

While Greg has kindly provided a solution that implements the Clipboard for the Range.Find.Replacement, it does require the overhead of copying the long string to the Clipboard. Additionally it has the associated vulnerablities and impositions of using the user's Clipboard.

When compared to a Microsoft workaround that employs Selection.Typext, a routine that basically takes the actual buffer as input, and was proven to work with Selection.Find, the Microsoft workaround offers a definate architectual advantage.

And finally with this application's implementation, while the document is being generated, it is not yet ".Visible" to the user.

So that brought me to the question...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top