Macro Lines Skipped

G

Glenn Sasscer

Wrote Auto-Open Macro to load text file from our server into Word in Word
2000. This works great in Word 2000. Unfortunately, Word 2003 skips over
lines in the format in the macro. When the macro laods a table and formats
it, it sets specific sizes in the macro which get skipped over when the macro
runs in Word 2003. If I step through the macro (F8), it works perfectly, but
when it runs on its own the lines get skipped.

When it comes to printing, the macro calls the printer dialog box in Word
2000, the user selects a printer, and the doc pritns, saves, and closes. In
Word 2003, the doc saves and closes before the doc has a chance to print.

What is hte best method to correct these siutations?
 
J

Jay Freedman

Glenn said:
Wrote Auto-Open Macro to load text file from our server into Word in
Word 2000. This works great in Word 2000. Unfortunately, Word 2003
skips over lines in the format in the macro. When the macro laods a
table and formats it, it sets specific sizes in the macro which get
skipped over when the macro runs in Word 2003. If I step through the
macro (F8), it works perfectly, but when it runs on its own the lines
get skipped.

When it comes to printing, the macro calls the printer dialog box in
Word 2000, the user selects a printer, and the doc pritns, saves, and
closes. In Word 2003, the doc saves and closes before the doc has a
chance to print.

What is hte best method to correct these siutations?

For the formatting issue it's impossible to tell without seeing the code and
the specific file you're trying to format. But a common problem is the use
of the Selection object (representing the actual cursor or selected text in
the document) instead of a Range object. The Selection object is so much
slower, because it forces screen updates and repagination, that VBA can
"lose track" of what it's executing. That's especially true if you're using
the Selection object in a table.

For the printing problem, the usual cause is omitting the optional parameter
named Background from the PrintOut method call. The default value (used when
the parameter is omitted) is True, meaning "use a background thread to
print, but let the foreground thread continue executing the next line of the
macro." If the next line (or one or two lines later) is the Close statement,
then the document is gone before the print spooler can get working. Instead,
you need to set Background:=False, meaning "don't use a background thread;
make the macro wait until the spooler completes and returns control to the
foreground thread."

If you need additional help with these problems, a better place would be the
VBA newgroup,
http://www.microsoft.com/office/community/en-us/default.mspx?dg=microsoft.public.word.vba.beginners.

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

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