Question

I am programmatically generating an Office Open XML document (Word 2007 format), and would like to have all the fields updated when the document I generate is first opened in Word.

When I researched this a while ago, the only way to do this was to run VB Script when the document opens. But VB Script doesn't run by default, and for this to work the user has to authorize scripts, which is more complicated than asking the user to do a "select-all, F9", and so this defeats the purpose.

Any suggestion?

Alex

Was it helpful?

Solution

Your research already showed the correct results. Using VBA or any other form of Word automation is the only way to go. Word nor OpenXML have an option to automatically update fields on open.

OTHER TIPS

There is a way to do this without VB Script.

You can set the field as dirty and it will update when the document is opened.

<w:fldSimple w:instr="TOC" w:dirty="true" />

If you have many fields you can update the settings in your document so that all fields are updated when the document is opened

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<w:settings xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
    <w:updateFields w:val="true" />
</w:settings>

However, these both have the downside of a confirmation dialog appearing when the document is opened that says "This document contains fields that may refer to other files. Do you want to update the fields in this document?"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top