Fields that do not replace mechanically pose an issue with many customers as a result of they do not bear in mind to replace them manually. Once you want this performance, use this VBA process.

asian-student-surf-internet-for-job-hunting-freelancer-blog-writer-picture-id1132736227.jpg

Picture: insjoy, Getty Photographs/iStockPhoto

The article Methods to replace a web page quantity reference in a Phrase doc makes use of fields to replace cross-references in a Microsoft Phrase doc. The issue is that the fields in use will not replace mechanically, so the consumer should bear in mind to take action. That is not superb as a result of it is a job that is straightforward to overlook. On this article, I will present you a built-in setting that updates the fields earlier than printing, after which I will present you a VBA answer.

SEE: 83 Excel ideas each consumer ought to grasp (eBioPic)

I am utilizing Microsoft 365 on a Home windows 10 64-bit system, however you should utilize earlier variations. Phrase On-line will not assist the options on this article. For fast entry to the VBA code, you possibly can obtain the demonstration .docm, .doc and .cls recordsdata.

Methods to replace when printing in Phrase

To replace a person discipline, click on on it and press F9 or right-click and choose Replace Area. To replace all references in a doc, press Ctrl + A, then press F9. Even in the event you solely have one or just a few, it is onerous to recollect to manually replace these fields. As a substitute, you possibly can set Phrase to at all times replace fields earlier than printing your doc as follows:

  1. Click on the File menu and select Choices or Extra after which Choices within the left pane.
  2. Select Show within the left pane.
  3. Within the Printing part, verify the Replace Fields Earlier than Printing choice (Determine A).
  4. Click on OK.

Determine A

wordupdatefieldmacro-a.jpg

  Select this feature to replace fields when printing.

As you would possibly suspect, this feature is proscribed. First, in the event you’re sending the doc by e mail you will not be printing, so this feature is ineffective. As well as, you won’t discover {that a} discipline does not replace if a bookmark or reference is damaged since you will not be viewing the doc earlier than updating when printing.

This feature has its place, however let’s take a look at a code answer that is extra reliable.

Methods to replace with VBA in Phrase

The VBA command to replace fields

ThisDocument.Fields.Replace

is straightforward to implement. Itemizing A reveals how straightforward it’s to replace all fields when closing a doc.

Itemizing A

Personal Sub Document_Close()

‘Replace all fields when closing doc.

    ThisDocument.Fields.Replace

Finish Sub

This process makes use of the Doc object’s Shut occasion. Which means, closing the doc triggers the occasion that updates all fields. It is slick and straightforward. The one actual drawback is deciding what occasion to make use of, and Shut makes probably the most sense to me. You need to use the Open occasion, however that will not replace fields after you modify the doc. 

You can set off each the Open and Shut occasions to cowl most conditions. As well as, verify the choice reviewed at first of this text to cowl virtually each attainable situation:

  • If the consumer prints the doc, the fields are up to date first.
  • If the consumer makes modifications and closes the doc earlier than emailing, the fields are up to date first.
  • If the consumer opens the doc and prints with out making modifications, the fields are up to date first.

There’s one risk that is not lined: The consumer opens the file, makes modifications, after which sends the file with out closing the doc, which is not possible as a result of most of us would shut and save the doc earlier than sending it.

SEE: Home windows 10: Lists of vocal instructions for speech recognition and dictation (free PDF) (eBioPic)

I’ve added the process in Itemizing A to the downloadable recordsdata. I am utilizing the demonstration recordsdata used within the linked article within the introduction. You’ll be able to work with any Phrase doc, however you may wish to add a discipline that does not replace mechanically to the physique of the doc. There are three pages. On web page 2 is a textual content reference. On web page 3, a cross-reference discipline returns the web page variety of the textual content reference on web page 2. Should you enter a web page between pages 1 and a pair of, the textual content reference strikes to web page Three and the cross-reference strikes to web page 4. Nonetheless, the cross-reference will nonetheless return web page 2 as a result of it will not replace mechanically. 

Should you resolve to enter the process manually, remember to save the workbook as a macro-enabled file in the event you’re utilizing a ribbon model or the process will not run. Should you’re utilizing a menu model, you possibly can skip this step. So as to add the process, press Alt + F11 to open the Visible Primary Editor. Within the Mission Explorer to the left, choose ThisDocument. You’ll be able to enter the code manually or import the downloadable .cls file. As well as, the process is within the downloadable .docm and .doc recordsdata. Should you enter the code manually, do not paste from this internet web page. As a substitute, copy the code right into a textual content editor after which paste that code into the ThisDocument module. Doing so will take away any phantom internet characters which may in any other case trigger errors.  

To make use of the process merely shut your doc. However first, in the event you’re utilizing an indication file, add a web page to the demonstration .docm or .doc file between pages 1 and web page 2 to maneuver the textual content reference on web page 2 to web page 3. The cross-reference discipline that was on web page Three is now on web page 4, but it surely will not replace mechanically. When prompted to save lots of if you shut the file, click on Save. Once you reopen the doc, any discipline that must be up to date will show the right outcome. To be taught extra about this demonstration file’s fields and its goal, learn the linked article within the introduction.

Should you discover this a bit too complicated, you needn’t use the demonstration file. You’ll be able to do this with any Phrase doc that comprises fields that do not replace mechanically.

This straightforward process has one limitation, which does not affect our particular instance: It updates fields solely in the primary story of the doc. It will not replace fields in headers, footers, footnotes or endnotes. That is not a problem for us as a result of Phrase would replace the {PageRef} discipline (the sector we’re utilizing) if it had been within the header or footer. 

The process in Itemizing A is an effective place to start out, however as talked about it has limitations. In a future article, I will present you easy methods to usurp the Save command to replace fields if you save the file. As well as, you possibly can stay up for an article that updates fields past the primary story. 

Additionally see

Leave a Reply