string limit when using selection.typetext?

L

Lucas Karpiuk

i've stored a very large string, myBody

Len(myBody) returns roughly 230,000

for some reason, when i try to

selection.typetext(myBody)

only about 16,000 characters are being inserted

am i just completely missing something, or is this something i should just
know and expect to work around (assuming the latter, what's the suggested
workaround?)

thanks in advance
 
H

Helmut Weber

Hi Lucas,

it is probably the method typetext,
which causes trouble.
Don't know why, but typetext reminds me
of typing letter by letter.

The following seems to work without a problem:

Sub Test0007()
Dim s As String
s = String(300000, "x")
Selection.Range = s
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
K

Klaus Linke

Yep, .TypeText is limited to 64kB.
..InsertAfter or .InsertBefore would be other alternatives.

Regards,
Klaus
 
J

Jonathan West

Lucas Karpiuk said:
i've stored a very large string, myBody

Len(myBody) returns roughly 230,000

for some reason, when i try to

selection.typetext(myBody)

only about 16,000 characters are being inserted

am i just completely missing something, or is this something i should just
know and expect to work around (assuming the latter, what's the suggested
workaround?)

Various methods of the Word object model do have limitations in the length
of strings they can take. I didn't know about this specific one, but I'm not
overly surprised. There are various options available to you.

1. See if different methods get round the limitation. For instance, try the
InsertAfter method instead of the TypeText method, or try assigning myBody
to the Selection.Text property.

2. Use the Mid function to create chunks of 15k or so, and insert them a
chunk at a time.
 
R

Russ

Lucas,
Another option is use:
=====Quote From VBA Help
InsertFile Method
See Also Example Applies To
Inserts all or part of the specified file.
Syntax
expression.InsertFile(FileName, Range, ConfirmConversions, Link, Attachment)
expression Required. An expression that returns a Range or Selection
object.
FileName Required String. The path and file name of the file to be
inserted. If you don't specify a path, Word assumes the file is in the
current folder.
Range Optional Variant. If the specified file is a Word document, this
parameter refers to a bookmark. If the file is another type (for example, a
Microsoft Excel worksheet), this parameter refers to a named range or a cell
range (for example, R1C1:R3C4).
ConfirmConversions Optional Variant. True to have Word prompt you to
confirm conversion when inserting files in formats other than the Word
Document format.
Link Optional Variant. True to insert the file by using an INCLUDETEXT
field.
Attachment Optional Variant. True to insert the file as an attachment to a
WordMail message (Windows only).
======UnQuote
 

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