Running a macro after document as finished rendering?

  • Thread starter Wayne Butterworth
  • Start date
W

Wayne Butterworth

Hi,

I'd like to update all of the fields in my document when the doc is opened. To do this, I have put ActiveDocument.Fields.Update in the AutoOpen() macro.
This works, except for the fields that are dependant on the number of pages in the document.

By examining the value of the "Number of pages" property in ActiveDocument.BuiltInDocumentProperties when the macro runs, I see that the number of pages is 3 ( there are actually 26 in my test document ) when the macro runs. If I manually run the macro, the number of pages in this property is correct.

I also found that if I stop the macro for a few seconds, eg by putting a Stop or breakpoint in, the Number of pages property gets updated correctly ( at the same time, I can see the scrollbar changing to reflect the increasing length of the document ).

So, it seems that the AutoOpen() macro runs after the document is loaded into memory ( the full contents are available to the macro ), but before the document is rendered. Is there a way to run a macro after the document is rendered / pagination is finished, or to pause AutoOpen() without user action to restart? Or is there perhaps a better way to update these fields?

thanks,


Wayne.


Submitted via EggHeadCafe - Software Developer Portal of Choice
WPF Datagrid as ComboBox Dropdown Part 2
http://www.eggheadcafe.com/tutorial...96-e24127040bbf/wpf-datagrid-as-combobox.aspx
 
J

Jay Freedman

Use the OnTime technique shown in
http://word.mvps.org/faqs/userforms/AutoExecUsertFm.htm. Just replace
the "Tempfm.Show" statement with the ActiveDocument.Fields.Update
statement. Of course, it would be appropriate to rename the ShowForm
macro to something like UpdateAll.

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

Wayne Butterworth

Thanks Jay.
That works nicely :)


Wayne.



Jay Freedman wrote:

Use the OnTime technique shown inhttp://word.mvps.
07-Apr-10

Use the OnTime technique shown i
http://word.mvps.org/faqs/userforms/AutoExecUsertFm.htm. Just replac
the "Tempfm.Show" statement with the ActiveDocument.Fields.Updat
statement. Of course, it would be appropriate to rename the ShowFor
macro to something like UpdateAll

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

Previous Posts In This Thread:


Submitted via EggHeadCafe - Software Developer Portal of Choice
BizTalk Configure and Send SMTP Mail Based on Message Within an Orchestration
http://www.eggheadcafe.com/tutorial...1-a2f309a021c2/biztalk-configure-and-sen.aspx
 

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