Problem using Selection.TypeText

H

Harry-Wishes

Hello

I have extracted the html code from a web table embedded in a Word document
and stored it in a variable string as shown below. The Word document is saved
as an html page in Word.


Dim html_string as Stringhtml_string
ActiveDocument.HTMLProject.HTMLProjectItems(1).Text
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, count:=1
Selection.TypeText Text:=html_string '''LINE 5 is the problem line

It works very well when I test the script on Word documents with small
embedded html tables with few rows and columns but not everything gets stored
for large tables beyond a certain number of rows and columns. The string gets
truncated after some point. The truncation seems to take place when I execute
line 5 above (Selection.TypeText Text:html_string). The "html_string"
variable itselfs retains all of the html code when I throw it's output to the
screen so, I know for a fact something is happening when I place the contents
into the active Word document using the Selection.TypeText method. Is there
a character size limit when using the Selection.TypeText method? If so, is
there a way around this?

Thanks

Harry_Wishes
 
J

Jay Freedman

There very well may be some internal limit on the size of the Text argument,
although I tested it with 3000 characters and it worked perfectly.

However, the whole use of Selection and its methods and properties is
unnecessary -- it treats the macro as if it were a phantom user hitting keys
on the keyboard, which has been discouraged (except by the braindead macro
recorder) since Word 95 and WordBasic. Try instead

Dim html_string as Stringhtml_string
html_string = ActiveDocument.HTMLProject.HTMLProjectItems(1).Text
ActiveDocument.Range.Text = html_string

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
K

Klaus Linke

Jay Freedman said:
There very well may be some internal limit on the size of the Text
argument, although I tested it with 3000 characters and it worked
perfectly.

Yes, it's limited to 64 kB ... maybe even 32 kB with Unicode text (...don't
remember -- it's a while I tested the latter).

..InsertAfter or .InsertBefore would be other alternatives, using Selection
or Ranges.

Regards,
Klaus
 
J

Jay Freedman

Yes, it's limited to 64 kB ... maybe even 32 kB with Unicode text (...don't
remember -- it's a while I tested the latter).

.InsertAfter or .InsertBefore would be other alternatives, using Selection
or Ranges.

Regards,
Klaus

Yes, I suspected it might be 32 kB, but I didn't have the patience to try that.
I doubt the OP's HTML is that big, so the problem probably lies somewhere else.
 

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