Sequential numbers to appear twice on each document

J

Jay Freedman

Set up the document with the bookmark for the first occurrence of the
number, as described in the article. Where you want the second occurrence,
insert a field

{ REF SerialNumber }

In the code, between the 'End With' and the 'ActiveDocument.Save'
statements, add the line

ActiveDocument.Fields.Update

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
A

Andy Pearlman

Jay Freedman said:
Set up the document with the bookmark for the first occurrence of the
number, as described in the article. Where you want the second occurrence,
insert a field

{ REF SerialNumber }

In the code, between the 'End With' and the 'ActiveDocument.Save'
statements, add the line

ActiveDocument.Fields.Update

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Hello Jay, hope you're still monitoring this site two years after you wrote
this. I am trying to do the same thing as the Code Numpty, but I can't get it
to work. After I place the bookmark "SerialNumber", I then scroll down to
where I want the repeat of that number, and click Insert/Field, scroll down
the field names list and select REF, then "SerialNumber" appears under
Bookmark Name and I select that, and click OK. I can see the repeat of the
Serial Number change to the correct number in the document on my screen, but
when I print, instead (in that location only) I get an error message:
"Reference source not found". What am I doing wrong?

Also, is there any way to run this without saving each copy of the document?
Once they're printed, I only need them on paper.

Thanks,
Andy Pearlman (Word 2003)
 
D

Doug Robbins - Word MVP

Instead of using a bookmark and a cross reference to the bookmark, at the
locations where you want the number to appear, insert the following field
codes, using Ctrl+F9 to create the field delimiters { }

{ DOCVARIABLE varSerialNumber }

Use Alt + F9 to toggle off the display of the field codes

Then use the following modified code:

Dim Message As String, Title As String, Default As String, NumCopies As Long


' Set prompt.
Message = "Enter the number of copies that you want to print"
' Set title.
Title = "Print"
' Set default.
Default = "1"

' Display message, title, and default value.
NumCopies = Val(InputBox(Message, Title, Default))
SerialNumber = System.PrivateProfileString("C:\Settings.Txt", _
"MacroSettings", "SerialNumber")

If SerialNumber = "" Then
SerialNumber = 1
End If

Set Rng1 = ActiveDocument.Bookmarks("SerialNumber").Range
Counter = 0

While Counter < NumCopies
With ActiveDocument
.Variables("varSerialNumber").Value = SerialNumber
.Range.Fields.Update
.PrintOut
End With
SerialNumber = SerialNumber + 1
Counter = Counter + 1
Wend

'Save the next number back to the Settings.txt file ready for the next use.
System.PrivateProfileString("C:\Settings.txt", "MacroSettings", _
"SerialNumber") = SerialNumber




--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.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