Forum Discussion
Lance_Kester
May 03, 2022Copper Contributor
Making a document number appear in several places
Hi I've created a Word template and used a macro to insert a document number which increases sequentially each time a new document is created from the template. This works fine, but I need to make t...
May 04, 2022
Instead of using a bookmark have your code assign the number to a document variable by using the code below to set the value of the variable and update the fields in the document, and where ever you want the number to appear in the document, insert a { DOCVARIABLE DocNum } field.
With ActiveDocument
.Variables("DocNum").Value = docnumber
.Range.Fields.Update
End With
With ActiveDocument
.Variables("DocNum").Value = docnumber
.Range.Fields.Update
End With
Lance_Kester
May 04, 2022Copper Contributor
Doug_Robbins_Word_MVP Many thanks for the prompt reply Doug. The code and field work fine in the document, but I can't get the DOCVARIABLE field to work if it's embedded in the header. Is there any way of doing this?
Regards
Lance Kester
- May 05, 2022
Use
Dim i as Long, j as Long
With ActiveDocument
.Variables("DocNum").Value = docnumber
.Range.Fields.Update
For i = 1 to .Sections.CountWith Sections(i)
For j = 1 to .Headers.Count
.Headers(j).Range.Fields.UpdateNext j
End With
Next i
End With
- Lance_KesterMay 09, 2022Copper ContributorThank you Doug, apologies for not replying sooner!