Sequential Numbering in Word 2003 and Recycling unused numbers

R

rachgg4

Once again, I am stuck in Macro world which is quickly consuming me :) It is
though, quite addictive and I am determined to win the fight I'm having with
my PC.
I work for a company which uses network servers so the document needs to be
accessed by different people but not necessarily at the same time. We operate
Windows XP Word 2003.
I am trying to create a document that will open with a sequential number,
but if the document is not used or opened accidentally then the number it has
generated needs to be recycled for auditing purposes. I seem to be able to
get the number to sequentially generate but the recycling of the number has
got me absolutely beat. I can’t for the life of me understand how to do it or
what I am doing wrong.
The other people who would be accessing the document are not very computer
literate and therefore I have tried to get the macro to AutoOpen so the
number is generated for them.
I have tried using code that MVP's have provided other users of the forum
with, but when I try incorporating all different macros I just make a big
mess.
I initially tried with an INI file but that got confusing too.
This is what I have so far ...

Sub AutoNew()
Dim Order As String
Dim sView As String

Order =
System.PrivateProfileString("S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems
Isolations\Drier 2 System Isolations Sequence.Txt", "MacroSettings",
"CertificateNumber", "Order")

If Order = "" Then
Order = 1
Else
Order = Order + 1
End If

System.PrivateProfileString("S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems
Isolations\Drier 2 System Isolations Sequence.Txt", "MacroSettings", "Order")
= Order

sView = ActiveWindow.View 'store the current view
With ActiveWindow
.View = wdPrintView 'set the document view to print layout
.ActivePane.View.SeekView = wdSeekCurrentPageHeader
With Selection
.WholeStory 'select any existing header text
.Delete Unit:=wdCharacter, Count:=1 'and delete it
.Font.Name = "Arial" 'Set the font characteristics
.Font.Bold = True 'of the inserted header
.Font.Italic = False 'if required
.Font.Size = "16"
.ParagraphFormat.Alignment = wdAlignParagraphRight

'Insert the new header
.TypeText Text:="Certificate No: " & Format(Order, "200#")
End With
.View.SeekView = wdSeekMainDocument 'Close the header view
.View = sView 'and restore the initial view

Order =
System.PrivateProfileString("S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems
Isolations\Drier 2 System Isolations Sequence.Txt", "MacroSettings", "Order")


ActiveDocument.SaveAs
FileName:="S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems Isolations\Drier 2
System Isolations" & Format(Order, "200#")

End Sub


Sub AutoOpen()
Dim Order As String
Dim sView As String

Order =
System.PrivateProfileString("S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems
Isolations\Drier 2 System Isolations Sequence.Txt", "MacroSettings", "Order")

'Create one and set the number to 1, otherwise increment the number

If Order = "" Then
Order = 1
Else
Order = Order + 1
End If

System.PrivateProfileString("S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems
Isolations\Drier 2 System Isolations Sequence.Txt", "InvoiceNumber", "Order")
= Order
sView = ActiveWindow.View 'store the current view
With ActiveWindow
.View = wdPrintView 'set the document view to print layout
.ActivePane.View.SeekView = wdSeekCurrentPageHeader
With Selection
.WholeStory 'select any existing header text
.Delete Unit:=wdCharacter, Count:=1 'and delete it
.Font.Name = "Arial" 'Set the font characteristics
.Font.Bold = True 'of the inserted header
.Font.Italic = False 'if required
.Font.Size = "16"
.ParagraphFormat.Alignment = wdAlignParagraphRight

'Insert the new header
.TypeText Text:="Certificate No: " & Format(Order, "200#")
End With
.View.SeekView = wdSeekMainDocument 'Close the header view
.View = sView 'and restore the initial view

Order =
System.PrivateProfileString("S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems
Isolations\Drier 2 System Isolations Sequence.Txt", "MacroSettings", "Order")


ActiveDocument.SaveAs
FileName:="S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems Isolations\Drier 2
System Isolations" & Format(Order, "200#")
End With
End Sub
'
' AutoOpen Macro
' Macro created 23/01/2010 by Rachel Watson
'

Sub AutoClose() 'Recycles number if document unsaved.'
If ActiveDocument.Name Like "S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems
Isolations\Drier 2 System Isolations*" Then
If MsgBox("This Certificate has not been saved. Do you want to save
before closing?", vbYesNo, "MacroSettings") = vbYes Then
Application.Dialogs(wdDialogFileSaveAs).Show
Else
If MsgBox("The current number will be recycled.", vbOKCancel,
"Recycle") = vbOK Then
SettingsFile = Options.DefaultFilePath(wdStartupPath) &
"\Settings.ini"
End If
ActiveDocument.Saved = True
ActiveDocument.AttachedTemplate.Saved = True
End If
End If

End Sub
'
' AutoClose Macro
' Macro created 23/01/2010 by Rachel Watson

If there is anyway at all you are able to give me any help or advice it
would be most appreciated.

Many thanks in advance,

rachgg4
 
R

rachgg4

Please ignore this post as the question has now been answered in an earlier
post. Thanks
 

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