flick: (Default)
Flick ([personal profile] flick) wrote2013-07-25 12:48 pm

Google fu fail

I'd like to create a Word document containing a numeric field that increments every time the file is opened.

I must be missing something, but all I'm finding online are guides based on Word 2003 that involve page-long macros and editing the register....

Does anyone know how do to do? Surely it must be possible, with some sort of fiddling with field codes? It's possible to create a custom field to be a counter, and to set things like date fields to auto-update on opening, so can I just combine the two?

It's years since I did anything serious in Word, and it was always my weakest of the three!
andrewducker: (Default)

[personal profile] andrewducker 2013-07-25 07:49 pm (UTC)(link)
It looks like there's no way to automatically update a field - but you can run some VBA on open. Looks somewhat complex though:
http://www.msofficeforums.com/word/7034-does-word-have-option-update-fields-automatically.html
ext_5856: (Legs)

[identity profile] flickgc.livejournal.com 2013-07-26 07:04 am (UTC)(link)
I'd settle for on print, rather than on open, but I still fail at the getting-it-to-increment thing.

I'm a little bemused that it's not easier, I must admit!

[identity profile] miramon.livejournal.com 2013-07-30 03:35 pm (UTC)(link)
Two options occur to me after thinking about it for a while, neither is perfect. Incidentally, I'm using Word 2010, other versions may differ. A lot depends on what you want to achieve.

There is a document property called Revision that auto-increments every time the document is saved. If you are only concerned with changes to the document, that might be what you want. You could also track the TotalEditingTime value which shows how many minutes have been spent editing the document.

Alternatively, if really need to know how many times it's been opened, create a custom property in the document and make it a number rather than text. Let's call it "Test". Then go into Developer/Visual Basic and add the following to the document:

Private Sub Document_Open()
ThisDocument.CustomDocumentProperties("Test") = ThisDocument.CustomDocumentProperties("Test") + 1
End Sub

The problem with this is that you have to save it as a macro-enabled document, and someone can open the document with macros disabled which will stop the number incrementing. Also, if you close the document without saving changes, it doesn't save the changed value (hence, I suspect, the code in the examples you found to save the number in the registry instead of in the document).

You can include a field with this property in the document (Insert/Quick Parts/Field then select Document Information, DocProperty, Test), but you may need to update the field before it shows the correct value.