TypeText returns before completing

J

jamie.fallon

Does TypeText return before completing?

I have a long macro that does loops. In the loop, it does a find, and
then uses TypeText to replace the found string, and then does a few
MoveDown's and deletes some stuff. If I step through the code line by
line it works fine, but when I run the macro, it seems to do the
delete before typeText is finished. I might have solved the issue by
putting a delay after the TypeText so that word can "catch up" to the
typing. But this seems like a bad solution. Can anyone answer the
above question about TypeText?
 
J

jamie.fallon

I found some suggestions in other threads. One person suggested
putting word into Normal view, and turning off auto-pagination. That
does seem to help. It lets the macro run faster.

Another person reccommended using Range instead of things like
Select.TypeText. I'm pretty sure that Selection.Typetext is
ascynchronous. Can anyone verify that Range commands are synchronous
(won't return until the change is made)?
 
J

Jay Freedman

I found some suggestions in other threads. One person suggested
putting word into Normal view, and turning off auto-pagination. That
does seem to help. It lets the macro run faster.

Another person reccommended using Range instead of things like
Select.TypeText. I'm pretty sure that Selection.Typetext is
ascynchronous. Can anyone verify that Range commands are synchronous
(won't return until the change is made)?

It's not that Range commands are synchronous, but they're orders of
magnitude faster than Selection.TypeText, especially if screen redrawing
hasn't been turned off. Assigning

myRange.Text = someStringValue

is nearly instantaneous, even if the string is very long.

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

jamie.fallon

It's not that Range commands are synchronous, but they're orders of
magnitude faster than Selection.TypeText, especially if screen redrawing
hasn't been turned off. Assigning

myRange.Text = someStringValue

is nearly instantaneous, even if the string is very long.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ:http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Gotcha. Thank you. Am I likely to be ok with Selection.TypeText if I
require background repagination to be turned off? In the future I'll
avoid using Selection.TypeText in a loop.

-Jamie
 
K

Klaus Linke

Am I likely to be ok with Selection.TypeText if I
require background repagination to be turned off?


Hi Jamie,

Another problem with .TypeText is that it's limited to 64kB (about 32000
characters).
If your strings might be longer, you'd need to replace it with
Selection.InsertAfter -- followed by Selection.Collapse(wdCollapseEnd) if
necessary.

Regards,
Klaus
 

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