Do you want this to be a visible counter that appears somewhere inside the
document? If so, one way (there are many) would be using a bookmarked number
and an AutoOpen macro.
Type the starting number (e.g., 1) anywhere in the document, select the
number, and insert a bookmark named Counter. With Bookmarks set to view,
gray brackets will appear around the number (Tools - Options - View -
Bookmarks).
Create the following macro, naming it AutoOpen, and saving it in the
document itself:
Sub AutoOpen()
Selection.GoTo What:=wdGoToBookmark, Name:="counter"
Selection.Copy
NewValue = Selection + 1
Selection.TypeText (Str(NewValue))
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="Counter"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub
Save/close the document.
Now (depending on your macro security settings), each time you open that
document, the number will be incremented by 1.
Above, I said "depending on your macro security settings." Here, I have
security set extremely high, so to get the macro to work, I had to digitally
sign it, and tell Word to always trust macros signed by me. Office comes
with a SelfCert program that creates a digital signature for use with your
own macros. For additional help, you might try one of the vba newsgroups
(e.g., microsoft.public.word.vba.general).
--
Herb Tyson MS MVP
Please respond in the newsgroups so everyone can follow along.
http://www.herbtyson.com
olleber said:
I have been attempting to insert a counter in a Word document which would
increment each time the document is openned.