Consecutive numbering in word documents

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all

Can anyone tell me, if it is possible to add a field to a word document in
which consecutive numbers will be added like this:
1 the first time the document is openend
2 the second time the document is opened
3 the third time
.... and so on (also if it's opened by different users)

Hope you get what I mean :-)

Jane - DK
 
Hi,

Dim WSHShell, RegKey, rkeyWord, Result
Set WSHShell = CreateObject("WScript.Shell")
RegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\MsWordNum\"

rkeyWord = WSHShell.RegRead(RegKey & "Word")
Dim xx As Integer
xx = Val(rkeyWord) + 1
Dim yy As String
yy = Right("00000" + Trim(Str(xx)), 5)
WSHShell.regwrite RegKey & "Word", yy

' here the code is to print in header the registry value
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1

Selection.TypeText Text:=yy + " C_ME_C "

Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"DATE \@ ""d/M/yyyy"" ", PreserveFormatting:=True

If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader


'to close the header / footer view
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

Please try the above code. I hope this helps !
Should there be any further queries, please feel free to contact me :
(e-mail address removed)

Reetesh B. Chhatpar
ShawMan Software Enterprises
www.shawmansoftware.com

Diamond is just another piece of coal that did well under pressure.
 

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

Back
Top