Auto update fields when opening document, problems.

S

s1004683

Hey,

I have a situation where I want to combine multiple source documents
into several target documents. When a source changes, the change has
to be visible in the target document too.

Example:
Source documents:
B1.doc
B2.doc
B3.doc
B4.doc

Target documents:
A1.doc (based on B1.doc, B2.doc)
A2.doc (based on B1.doc, B2.doc, B3.doc)
etc.

The solution
I choose "Insert> File" to add the source documents to the
targetdocuments. Now the sourcedocuments are added as fields in the
target. These fields has to be updated automaticly when the target
document is opened. I am using the following macro to do that:
http://support.microsoft.com/kb/212703

Now, this macro has to run any time when a user opens a target
document. This can be done by give the macro name "AutoExec"(http://
support.microsoft.com/kb/211659)

But there's a problem:

"The AutoExec macro runs when Word starts if the AutoExec macro was
saved as part of the default (Normal.dot) template or if it was saved
as part of a global add-in."

I cannot access the normal.dot on every computer, everything has to be
in the document itself. So AutoExec is not the solution I can use.

There is a second problem. In the top of the page is a Table of
Contents. When updating all the fields, Word is taking the following
steps:
- Empty all the fields
- Update all the fields from top to bottom, beginning with the Table
of Contents. But hey! All the fields are empty, so the Table of
Contents aren't correct
- Update the rest of the fields.

I want to update the Table of Contents on the end, also automatic. How
can I do this?

Can anyone solve me with this problems? Or is there an alternative way
to reach my goal? Thanks!
 
G

Graham Mayor

Use IncludeText fields to include your documents.

Use an Autoopen macro in the document to force an update to the fields
(though there is no way to force users to allow the macro to run if they
don't want to).

Sub AutoOpen()
Dim oStory As Range
Dim oTOC As TableOfContents
For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Wend
End If
Next oStory
Set oStory = Nothing
For Each oTOC In ActiveDocument.TablesOfContents
oTOC.Update
Next oTOC
End Sub

Should work for most circumstances involving IncludeText fields and TOC
fields


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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