auto number a word document each time it is opened

Hi there,

I would like to know how to have a number update automatically each time the 
document is opened. I have tried all the avenues I know and still have had no 
luck.
I am using word 2003 and have no experience with macros, however I am keen 
to learn. I am struggling to get the below advice to previous users " 
http://www.word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm. "
to work for me. It keeps coming up with error messages after I have created 
the macro, the main one being "Compile Error: Expected Function or variable" 
for the "Order =" and then will not attach it to my document. 
I know many others have asked how to do this, I'm sorry if this is sounding 
repetitive.
Many thanks in advance to anyone able to help me.

Kind regards
0
Utf
1/16/2010 4:58:01 PM
word.newusers 801 articles. 0 followers. Follow

9 Replies
1364 Views

Similar Articles

[PageSpeed] 55

The easiest way for you to do that is go to the File>Properties dialog and 
then go to the Custom tab and in the Name: field, type DocNumber and in the 
Value: field, type the starting number that you wish to use e.g. 1, then 
click on Add, then click on OK.

Then in your document, and in the location where you want the number to 
appear, go to the Insert>Field dialog and scroll down through the list of 
fields to the DocProperty field and then in the list of properties, select 
the DocNumber item from the list.  When you click OK, the starting number 
that you entered will appear in the document.

To get this number to be updated each time the document is opened, create 
the following macro

Sub AutoOpen()
On Error GoTo EndThis  'Exits the routine if the Custom Document Property 
DocNumber has not be added to the document
With ActiveDocument
    .CustomDocumentProperties("DocNumber") = 
..CustomDocumentProperties("DocNumber") + 1
    .Range.Fields.Update
End With

EndThis:

End Sub

-- 
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

"rachgg4" <rachgg4@discussions.microsoft.com> wrote in message 
news:57698EEC-42B6-4F7E-B5FC-B16014EEA556@microsoft.com...
> Hi there,
>
> I would like to know how to have a number update automatically each time 
> the
> document is opened. I have tried all the avenues I know and still have had 
> no
> luck.
> I am using word 2003 and have no experience with macros, however I am keen
> to learn. I am struggling to get the below advice to previous users "
> http://www.word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm. "
> to work for me. It keeps coming up with error messages after I have 
> created
> the macro, the main one being "Compile Error: Expected Function or 
> variable"
> for the "Order =" and then will not attach it to my document.
> I know many others have asked how to do this, I'm sorry if this is 
> sounding
> repetitive.
> Many thanks in advance to anyone able to help me.
>
> Kind regards 

0
Doug
1/16/2010 8:50:00 PM
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



"Doug Robbins - Word MVP" wrote:

> The easiest way for you to do that is go to the File>Properties dialog and 
> then go to the Custom tab and in the Name: field, type DocNumber and in the 
> Value: field, type the starting number that you wish to use e.g. 1, then 
> click on Add, then click on OK.
> 
> Then in your document, and in the location where you want the number to 
> appear, go to the Insert>Field dialog and scroll down through the list of 
> fields to the DocProperty field and then in the list of properties, select 
> the DocNumber item from the list.  When you click OK, the starting number 
> that you entered will appear in the document.
> 
> To get this number to be updated each time the document is opened, create 
> the following macro
> 
> Sub AutoOpen()
> On Error GoTo EndThis  'Exits the routine if the Custom Document Property 
> DocNumber has not be added to the document
> With ActiveDocument
>     .CustomDocumentProperties("DocNumber") = 
> ..CustomDocumentProperties("DocNumber") + 1
>     .Range.Fields.Update
> End With
> 
> EndThis:
> 
> End Sub
> 
> -- 
> 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
> 
> "rachgg4" <rachgg4@discussions.microsoft.com> wrote in message 
> news:57698EEC-42B6-4F7E-B5FC-B16014EEA556@microsoft.com...
> > Hi there,
> >
> > I would like to know how to have a number update automatically each time 
> > the
> > document is opened. I have tried all the avenues I know and still have had 
> > no
> > luck.
> > I am using word 2003 and have no experience with macros, however I am keen
> > to learn. I am struggling to get the below advice to previous users "
> > http://www.word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm. "
> > to work for me. It keeps coming up with error messages after I have 
> > created
> > the macro, the main one being "Compile Error: Expected Function or 
> > variable"
> > for the "Order =" and then will not attach it to my document.
> > I know many others have asked how to do this, I'm sorry if this is 
> > sounding
> > repetitive.
> > Many thanks in advance to anyone able to help me.
> >
> > Kind regards 
> 
> .
> 
0
Utf
1/23/2010 3:09:02 AM
You need to save the 'document' as a template and create new documents from 
it, using an autonew macro to apply the number.

If your macro writes the next number to the ini file (which needs to be in a 
location anyone using the template can access) then if the document is 
closed without saving, you need an autoclose macro to decrement the stored 
number to enable the number to be re-used. It is not possible for the macro 
to second guess whether the user intended to keep a saved number or not. As 
someone will inevitably screw it up, you need a macro to reset the start 
number.

Create a new module in the template - 
http://www.gmayor.com/installing_macro.htm and try the following, which 
seems to do what your macros attempted to do.

Option Explicit
Private CertNo As String
Private oHeader As Range
Private sName As String
Const sPath = "S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems Isolations\"
Sub AutoNew()
CertNo = System.PrivateProfileString(sPath & _
"Drier 2 System Isolations Sequence.ini", _
"MacroSettings", "CertificateNumber")
If CertNo = "" Then
    CertNo = 1
Else
    CertNo = CertNo + 1
End If
If ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Exists Then
    Set oHeader = 
ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
Else
    Set oHeader = 
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
End If
With oHeader
    .Text = "Certificate No: " & Format(CertNo, "200#")
    .Font.Bold = True 'of the inserted header
    .Font.Italic = False 'if required
    .Font.Size = "16"
    .ParagraphFormat.Alignment = wdAlignParagraphRight
End With
System.PrivateProfileString(sPath & _
"Drier 2 System Isolations Sequence.ini", _
"MacroSettings", "CertificateNumber") = CertNo
End Sub
Sub SaveCertificateAs()
CertNo = System.PrivateProfileString(sPath & _
"Drier 2 System Isolations Sequence.ini", _
"MacroSettings", "CertificateNumber")
If Not ActiveDocument.Path = "" Then
    ActiveDocument.Save
Else
    With Dialogs(wdDialogFileSaveAs)
        .Name = sPath & "Drier 2 System Isolations " _
        & Format(CertNo, "200#")
        .Show
    End With
End If
ActiveDocument.Close
End Sub

Sub AutoClose() 'Recycles number if document unsaved.'
CertNo = System.PrivateProfileString(sPath & _
"Drier 2 System Isolations Sequence.ini", _
"MacroSettings", "CertificateNumber")
If Len(ActiveDocument.Path) = 0 Then
    If MsgBox("This Certificate has not been saved." & vbCr & _
        "Do you want to save before closing?", _
        vbYesNo, "MacroSettings") = vbYes Then
        With Dialogs(wdDialogFileSaveAs)
            .Name = sPath & "Drier 2 System Isolations " _
            & Format(CertNo, "200#")
            .Show
        End With
    Else
        MsgBox "The current number " & _
        "will be recycled.", vbOKCancel, _
        "Recycle"
    End If
    ActiveDocument.Saved = True
End If
End Sub

Sub ResetStartNo()
CertNo = System.PrivateProfileString(sPath & _
"Drier 2 System Isolations Sequence.ini", _
"MacroSettings", "CertificateNumber")
CertNo = InputBox("Reset next certificate number?", "Reset", CertNo)
System.PrivateProfileString(sPath & _
"Drier 2 System Isolations Sequence.ini", _
"MacroSettings", "CertificateNumber") = CertNo - 1
End Sub




"rachgg4" <rachgg4@discussions.microsoft.com> wrote in message 
news:28C57B35-CDFF-4218-B0B4-C6EDB901857A@microsoft.com...
> 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
>
>
>
> "Doug Robbins - Word MVP" wrote:
>
>> The easiest way for you to do that is go to the File>Properties dialog 
>> and
>> then go to the Custom tab and in the Name: field, type DocNumber and in 
>> the
>> Value: field, type the starting number that you wish to use e.g. 1, then
>> click on Add, then click on OK.
>>
>> Then in your document, and in the location where you want the number to
>> appear, go to the Insert>Field dialog and scroll down through the list of
>> fields to the DocProperty field and then in the list of properties, 
>> select
>> the DocNumber item from the list.  When you click OK, the starting number
>> that you entered will appear in the document.
>>
>> To get this number to be updated each time the document is opened, create
>> the following macro
>>
>> Sub AutoOpen()
>> On Error GoTo EndThis  'Exits the routine if the Custom Document Property
>> DocNumber has not be added to the document
>> With ActiveDocument
>>     .CustomDocumentProperties("DocNumber") =
>> ..CustomDocumentProperties("DocNumber") + 1
>>     .Range.Fields.Update
>> End With
>>
>> EndThis:
>>
>> End Sub
>>
>> -- 
>> 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
>>
>> "rachgg4" <rachgg4@discussions.microsoft.com> wrote in message
>> news:57698EEC-42B6-4F7E-B5FC-B16014EEA556@microsoft.com...
>> > Hi there,
>> >
>> > I would like to know how to have a number update automatically each 
>> > time
>> > the
>> > document is opened. I have tried all the avenues I know and still have 
>> > had
>> > no
>> > luck.
>> > I am using word 2003 and have no experience with macros, however I am 
>> > keen
>> > to learn. I am struggling to get the below advice to previous users "
>> > http://www.word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm. "
>> > to work for me. It keeps coming up with error messages after I have
>> > created
>> > the macro, the main one being "Compile Error: Expected Function or
>> > variable"
>> > for the "Order =" and then will not attach it to my document.
>> > I know many others have asked how to do this, I'm sorry if this is
>> > sounding
>> > repetitive.
>> > Many thanks in advance to anyone able to help me.
>> >
>> > Kind regards
>>
>> .
>> 


0
Graham
1/23/2010 9:50:58 AM
I am so grateful for all the help.
This is absolutely brilliant!! 
Only one thing that won't work properly is the recycling of the number. It 
will ask if I want to save changes and I choose 'no' then asks 'Do I want to 
recycle the number? (e.g 2001) and I say 'yes' but when the doc template is 
opened for the next document to be generated, it has the next number as 
'2002' not '2001'. Have I missed something yet again?
Sorry if I am not quite getting it.
Thanks in advance
rachgg4

"Graham Mayor" wrote:

> You need to save the 'document' as a template and create new documents from 
> it, using an autonew macro to apply the number.
> 
> If your macro writes the next number to the ini file (which needs to be in a 
> location anyone using the template can access) then if the document is 
> closed without saving, you need an autoclose macro to decrement the stored 
> number to enable the number to be re-used. It is not possible for the macro 
> to second guess whether the user intended to keep a saved number or not. As 
> someone will inevitably screw it up, you need a macro to reset the start 
> number.
> 
> Create a new module in the template - 
> http://www.gmayor.com/installing_macro.htm and try the following, which 
> seems to do what your macros attempted to do.
> 
> Option Explicit
> Private CertNo As String
> Private oHeader As Range
> Private sName As String
> Const sPath = "S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems Isolations\"
> Sub AutoNew()
> CertNo = System.PrivateProfileString(sPath & _
> "Drier 2 System Isolations Sequence.ini", _
> "MacroSettings", "CertificateNumber")
> If CertNo = "" Then
>     CertNo = 1
> Else
>     CertNo = CertNo + 1
> End If
> If ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Exists Then
>     Set oHeader = 
> ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
> Else
>     Set oHeader = 
> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
> End If
> With oHeader
>     .Text = "Certificate No: " & Format(CertNo, "200#")
>     .Font.Bold = True 'of the inserted header
>     .Font.Italic = False 'if required
>     .Font.Size = "16"
>     .ParagraphFormat.Alignment = wdAlignParagraphRight
> End With
> System.PrivateProfileString(sPath & _
> "Drier 2 System Isolations Sequence.ini", _
> "MacroSettings", "CertificateNumber") = CertNo
> End Sub
> Sub SaveCertificateAs()
> CertNo = System.PrivateProfileString(sPath & _
> "Drier 2 System Isolations Sequence.ini", _
> "MacroSettings", "CertificateNumber")
> If Not ActiveDocument.Path = "" Then
>     ActiveDocument.Save
> Else
>     With Dialogs(wdDialogFileSaveAs)
>         .Name = sPath & "Drier 2 System Isolations " _
>         & Format(CertNo, "200#")
>         .Show
>     End With
> End If
> ActiveDocument.Close
> End Sub
> 
> Sub AutoClose() 'Recycles number if document unsaved.'
> CertNo = System.PrivateProfileString(sPath & _
> "Drier 2 System Isolations Sequence.ini", _
> "MacroSettings", "CertificateNumber")
> If Len(ActiveDocument.Path) = 0 Then
>     If MsgBox("This Certificate has not been saved." & vbCr & _
>         "Do you want to save before closing?", _
>         vbYesNo, "MacroSettings") = vbYes Then
>         With Dialogs(wdDialogFileSaveAs)
>             .Name = sPath & "Drier 2 System Isolations " _
>             & Format(CertNo, "200#")
>             .Show
>         End With
>     Else
>         MsgBox "The current number " & _
>         "will be recycled.", vbOKCancel, _
>         "Recycle"
>     End If
>     ActiveDocument.Saved = True
> End If
> End Sub
> 
> Sub ResetStartNo()
> CertNo = System.PrivateProfileString(sPath & _
> "Drier 2 System Isolations Sequence.ini", _
> "MacroSettings", "CertificateNumber")
> CertNo = InputBox("Reset next certificate number?", "Reset", CertNo)
> System.PrivateProfileString(sPath & _
> "Drier 2 System Isolations Sequence.ini", _
> "MacroSettings", "CertificateNumber") = CertNo - 1
> End Sub
> 
> 
> 
> 
> "rachgg4" <rachgg4@discussions.microsoft.com> wrote in message 
> news:28C57B35-CDFF-4218-B0B4-C6EDB901857A@microsoft.com...
> > 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
> >
> >
> >
> > "Doug Robbins - Word MVP" wrote:
> >
> >> The easiest way for you to do that is go to the File>Properties dialog 
> >> and
> >> then go to the Custom tab and in the Name: field, type DocNumber and in 
> >> the
> >> Value: field, type the starting number that you wish to use e.g. 1, then
> >> click on Add, then click on OK.
> >>
> >> Then in your document, and in the location where you want the number to
> >> appear, go to the Insert>Field dialog and scroll down through the list of
> >> fields to the DocProperty field and then in the list of properties, 
> >> select
> >> the DocNumber item from the list.  When you click OK, the starting number
> >> that you entered will appear in the document.
> >>
> >> To get this number to be updated each time the document is opened, create
> >> the following macro
> >>
> >> Sub AutoOpen()
> >> On Error GoTo EndThis  'Exits the routine if the Custom Document Property
> >> DocNumber has not be added to the document
> >> With ActiveDocument
> >>     .CustomDocumentProperties("DocNumber") =
> >> ..CustomDocumentProperties("DocNumber") + 1
> >>     .Range.Fields.Update
> >> End With
> >>
> >> EndThis:
> >>
> >> End Sub
0
Utf
1/23/2010 7:53:01 PM
Oops! My fault. The following version should fix the renumbering issues. Do 
note however that when inserting the number as plain text (as in this 
instance) you cannot change the number of the current document. (see later)


Option Explicit
Private CertNo As String
Private oHeader As Range
Private sName As String
Private oVars As Variables
Const sPath = "S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems Isolations\"
Sub AutoNew()
Set oVars = ActiveDocument.Variables
CertNo = System.PrivateProfileString(sPath & _
"Drier 2 System Isolations Sequence.ini", _
"MacroSettings", "CertificateNumber")
If CertNo = "" Then
    CertNo = 1
Else
    CertNo = CertNo + 1
End If
oVars("varCertNo").Value = CertNo
If ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Exists Then
    Set oHeader = 
ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
Else
    Set oHeader = 
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
End If
With oHeader
    .Text = "Certificate No: " & Format(CertNo, "200#")
    .Font.Bold = True 'of the inserted header
    .Font.Italic = False 'if required
    .Font.Size = "16"
    .ParagraphFormat.Alignment = wdAlignParagraphRight
End With
System.PrivateProfileString(sPath & _
"Drier 2 System Isolations Sequence.ini", _
"MacroSettings", "CertificateNumber") = CertNo
End Sub
Sub SaveCertificateAs()
CertNo = System.PrivateProfileString(sPath & _
"Drier 2 System Isolations Sequence.ini", _
"MacroSettings", "CertificateNumber")
If Not ActiveDocument.Path = "" Then
    ActiveDocument.Save
Else
    With Dialogs(wdDialogFileSaveAs)
        .Name = sPath & "Drier 2 System Isolations " _
        & Format(CertNo, "200#")
        .Show
    End With
End If
ActiveDocument.Close
End Sub

Sub AutoClose() 'Recycles number if document unsaved.'
Set oVars = ActiveDocument.Variables
CertNo = System.PrivateProfileString(sPath & _
"Drier 2 System Isolations Sequence.ini", _
"MacroSettings", "CertificateNumber")
If Len(ActiveDocument.Path) = 0 Then
    If MsgBox("This Certificate has not been saved." & vbCr & _
        "Do you want to save before closing?", _
        vbYesNo, "MacroSettings") = vbYes Then
        With Dialogs(wdDialogFileSaveAs)
            .Name = sPath & "Drier 2 System Isolations " _
            & Format(CertNo, "200#")
            .Show
        End With
    Else
        If CertNo = oVars("varCertNo") Then
            MsgBox "The current number " & _
            "will be recycled.", vbOKCancel, _
            "Recycle"
            System.PrivateProfileString(sPath & _
            "Drier 2 System Isolations Sequence.ini", _
            "MacroSettings", "CertificateNumber") = CertNo - 1
        End If
    End If
    ActiveDocument.Saved = True
End If
End Sub

Sub ResetStartNo()
CertNo = System.PrivateProfileString(sPath & _
"Drier 2 System Isolations Sequence.ini", _
"MacroSettings", "CertificateNumber")
CertNo = InputBox("Reset next certificate number?", "Reset", CertNo)
System.PrivateProfileString(sPath & _
"Drier 2 System Isolations Sequence.ini", _
"MacroSettings", "CertificateNumber") = CertNo - 1
End Sub

Having looked again at the macros, I felt that it might make more sense to 
the user to insert the number with a docvariable field rather than as plain 
text. This allows the current document to be updated when the number is 
reset. It needed a few extra lines of code to ensure that documents 
displayed and were saved with the right number, but the principles involved 
are much the same. I am however puzzled why you format the numbers as 200#. 
Why not simply set the start number as 2001? However I have left it as you 
had it.

Option Explicit
Private CertNo As String
Private oHeader As Range
Private oHead As HeaderFooter
Private oField As Field
Dim oRng As Range
Private sName As String
Private oVars As Variables
Const sPath = "S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems Isolations\"
Sub AutoNew()
Set oVars = ActiveDocument.Variables
CertNo = System.PrivateProfileString(sPath & _
"Drier 2 System Isolations Sequence.ini", _
"MacroSettings", "CertificateNumber")
If CertNo = "" Then
    CertNo = 1
Else
    CertNo = CertNo + 1
End If
oVars("varCertNo").Value = CertNo
oVars("varSaveNo").Value = CertNo
If ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Exists Then
    Set oHeader = 
ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
Else
    Set oHeader = 
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
End If
With oHeader
    .Text = "Certificate No: "
    .Font.Bold = True 'of the inserted header
    .Font.Italic = False 'if required
    .Font.Size = "16"
    .ParagraphFormat.Alignment = wdAlignParagraphRight
    .Collapse wdCollapseEnd
    .Fields.Add oHeader, wdFieldDocVariable, _
    """varCertNo"" \# ""200#""", False
    .Fields.Update
End With
System.PrivateProfileString(sPath & _
"Drier 2 System Isolations Sequence.ini", _
"MacroSettings", "CertificateNumber") = CertNo
End Sub
Sub SaveCertificateAs()
CertNo = System.PrivateProfileString(sPath & _
"Drier 2 System Isolations Sequence.ini", _
"MacroSettings", "CertificateNumber")
If Not ActiveDocument.Path = "" Then
    ActiveDocument.Save
Else
    With Dialogs(wdDialogFileSaveAs)
        .Name = sPath & "Drier 2 System Isolations 200" _
        & ActiveDocument.Variables("varSaveNo")
        .Show
    End With
End If
ActiveDocument.Close
End Sub

Sub AutoClose() 'Recycles number if document unsaved.'
Set oVars = ActiveDocument.Variables
CertNo = System.PrivateProfileString(sPath & _
"Drier 2 System Isolations Sequence.ini", _
"MacroSettings", "CertificateNumber")
If Len(ActiveDocument.Path) = 0 Then
    If MsgBox("This Certificate has not been saved." & vbCr & _
        "Do you want to save before closing?", _
        vbYesNo, "MacroSettings") = vbYes Then
        With Dialogs(wdDialogFileSaveAs)
            .Name = sPath & "Drier 2 System Isolations 200" _
            & oVars("VarSaveNo").Value
            .Show
        End With
    Else
        If CertNo = oVars("varCertNo") Then
            MsgBox "The current number " & _
            "will be recycled.", vbOKCancel, _
            "Recycle"
            System.PrivateProfileString(sPath & _
            "Drier 2 System Isolations Sequence.ini", _
            "MacroSettings", "CertificateNumber") = CertNo - 1
        End If
    End If
    ActiveDocument.Saved = True
End If
End Sub

Sub ResetStartNo()
Set oVars = ActiveDocument.Variables

CertNo = System.PrivateProfileString(sPath & _
"Drier 2 System Isolations Sequence.ini", _
"MacroSettings", "CertificateNumber")

CertNo = InputBox("Reset next certificate number?", _
"Reset", CertNo)

oVars("varSaveNo").Value = CertNo

System.PrivateProfileString(sPath & _
"Drier 2 System Isolations Sequence.ini", _
"MacroSettings", "CertificateNumber") = CertNo

oVars("varCertNo").Value = CertNo

For Each oHead In ActiveDocument.Sections(1).Headers
    If oHead.Exists Then
        For Each oField In oHead.Range.Fields
            oField.Update
        Next oField
    End If
Next oHead
End Sub


-- 
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


"rachgg4" <rachgg4@discussions.microsoft.com> wrote in message 
news:A9165EE7-AA80-4608-AD66-9BD8FCB6A49F@microsoft.com...
>I am so grateful for all the help.
> This is absolutely brilliant!!
> Only one thing that won't work properly is the recycling of the number. It
> will ask if I want to save changes and I choose 'no' then asks 'Do I want 
> to
> recycle the number? (e.g 2001) and I say 'yes' but when the doc template 
> is
> opened for the next document to be generated, it has the next number as
> '2002' not '2001'. Have I missed something yet again?
> Sorry if I am not quite getting it.
> Thanks in advance
> rachgg4
>
> "Graham Mayor" wrote:
>
>> You need to save the 'document' as a template and create new documents 
>> from
>> it, using an autonew macro to apply the number.
>>
>> If your macro writes the next number to the ini file (which needs to be 
>> in a
>> location anyone using the template can access) then if the document is
>> closed without saving, you need an autoclose macro to decrement the 
>> stored
>> number to enable the number to be re-used. It is not possible for the 
>> macro
>> to second guess whether the user intended to keep a saved number or not. 
>> As
>> someone will inevitably screw it up, you need a macro to reset the start
>> number.
>>
>> Create a new module in the template -
>> http://www.gmayor.com/installing_macro.htm and try the following, which
>> seems to do what your macros attempted to do.
>>
>> Option Explicit
>> Private CertNo As String
>> Private oHeader As Range
>> Private sName As String
>> Const sPath = "S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems Isolations\"
>> Sub AutoNew()
>> CertNo = System.PrivateProfileString(sPath & _
>> "Drier 2 System Isolations Sequence.ini", _
>> "MacroSettings", "CertificateNumber")
>> If CertNo = "" Then
>>     CertNo = 1
>> Else
>>     CertNo = CertNo + 1
>> End If
>> If ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Exists 
>> Then
>>     Set oHeader =
>> ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
>> Else
>>     Set oHeader =
>> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
>> End If
>> With oHeader
>>     .Text = "Certificate No: " & Format(CertNo, "200#")
>>     .Font.Bold = True 'of the inserted header
>>     .Font.Italic = False 'if required
>>     .Font.Size = "16"
>>     .ParagraphFormat.Alignment = wdAlignParagraphRight
>> End With
>> System.PrivateProfileString(sPath & _
>> "Drier 2 System Isolations Sequence.ini", _
>> "MacroSettings", "CertificateNumber") = CertNo
>> End Sub
>> Sub SaveCertificateAs()
>> CertNo = System.PrivateProfileString(sPath & _
>> "Drier 2 System Isolations Sequence.ini", _
>> "MacroSettings", "CertificateNumber")
>> If Not ActiveDocument.Path = "" Then
>>     ActiveDocument.Save
>> Else
>>     With Dialogs(wdDialogFileSaveAs)
>>         .Name = sPath & "Drier 2 System Isolations " _
>>         & Format(CertNo, "200#")
>>         .Show
>>     End With
>> End If
>> ActiveDocument.Close
>> End Sub
>>
>> Sub AutoClose() 'Recycles number if document unsaved.'
>> CertNo = System.PrivateProfileString(sPath & _
>> "Drier 2 System Isolations Sequence.ini", _
>> "MacroSettings", "CertificateNumber")
>> If Len(ActiveDocument.Path) = 0 Then
>>     If MsgBox("This Certificate has not been saved." & vbCr & _
>>         "Do you want to save before closing?", _
>>         vbYesNo, "MacroSettings") = vbYes Then
>>         With Dialogs(wdDialogFileSaveAs)
>>             .Name = sPath & "Drier 2 System Isolations " _
>>             & Format(CertNo, "200#")
>>             .Show
>>         End With
>>     Else
>>         MsgBox "The current number " & _
>>         "will be recycled.", vbOKCancel, _
>>         "Recycle"
>>     End If
>>     ActiveDocument.Saved = True
>> End If
>> End Sub
>>
>> Sub ResetStartNo()
>> CertNo = System.PrivateProfileString(sPath & _
>> "Drier 2 System Isolations Sequence.ini", _
>> "MacroSettings", "CertificateNumber")
>> CertNo = InputBox("Reset next certificate number?", "Reset", CertNo)
>> System.PrivateProfileString(sPath & _
>> "Drier 2 System Isolations Sequence.ini", _
>> "MacroSettings", "CertificateNumber") = CertNo - 1
>> End Sub
>>
>>
>>
>>
>> "rachgg4" <rachgg4@discussions.microsoft.com> wrote in message
>> news:28C57B35-CDFF-4218-B0B4-C6EDB901857A@microsoft.com...
>> > 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
>> >
>> >
>> >
>> > "Doug Robbins - Word MVP" wrote:
>> >
>> >> The easiest way for you to do that is go to the File>Properties dialog
>> >> and
>> >> then go to the Custom tab and in the Name: field, type DocNumber and 
>> >> in
>> >> the
>> >> Value: field, type the starting number that you wish to use e.g. 1, 
>> >> then
>> >> click on Add, then click on OK.
>> >>
>> >> Then in your document, and in the location where you want the number 
>> >> to
>> >> appear, go to the Insert>Field dialog and scroll down through the list 
>> >> of
>> >> fields to the DocProperty field and then in the list of properties,
>> >> select
>> >> the DocNumber item from the list.  When you click OK, the starting 
>> >> number
>> >> that you entered will appear in the document.
>> >>
>> >> To get this number to be updated each time the document is opened, 
>> >> create
>> >> the following macro
>> >>
>> >> Sub AutoOpen()
>> >> On Error GoTo EndThis  'Exits the routine if the Custom Document 
>> >> Property
>> >> DocNumber has not be added to the document
>> >> With ActiveDocument
>> >>     .CustomDocumentProperties("DocNumber") =
>> >> ..CustomDocumentProperties("DocNumber") + 1
>> >>     .Range.Fields.Update
>> >> End With
>> >>
>> >> EndThis:
>> >>
>> >> End Sub 


0
Graham
1/24/2010 8:07:46 AM
I have just spotted another glitch :(

Change both instances of

With Dialogs(wdDialogFileSaveAs)
        .Name = sPath & "Drier 2 System Isolations " _
        & Format(CertNo, "200#")
        .Show
End With

to

With Dialogs(wdDialogFileSaveAs)
            .Name = sPath & "Drier 2 System Isolations " _
            & Format(ActiveDocument.Variables("varSaveNo"), "200#")
            .Show
 End With


-- 
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


"Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message 
news:uCTqQxMnKHA.5520@TK2MSFTNGP05.phx.gbl...
> Oops! My fault. The following version should fix the renumbering issues. 
> Do note however that when inserting the number as plain text (as in this 
> instance) you cannot change the number of the current document. (see 
> later)
>
>
> Option Explicit
> Private CertNo As String
> Private oHeader As Range
> Private sName As String
> Private oVars As Variables
> Const sPath = "S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems Isolations\"
> Sub AutoNew()
> Set oVars = ActiveDocument.Variables
> CertNo = System.PrivateProfileString(sPath & _
> "Drier 2 System Isolations Sequence.ini", _
> "MacroSettings", "CertificateNumber")
> If CertNo = "" Then
>    CertNo = 1
> Else
>    CertNo = CertNo + 1
> End If
> oVars("varCertNo").Value = CertNo
> If ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Exists Then
>    Set oHeader = 
> ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
> Else
>    Set oHeader = 
> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
> End If
> With oHeader
>    .Text = "Certificate No: " & Format(CertNo, "200#")
>    .Font.Bold = True 'of the inserted header
>    .Font.Italic = False 'if required
>    .Font.Size = "16"
>    .ParagraphFormat.Alignment = wdAlignParagraphRight
> End With
> System.PrivateProfileString(sPath & _
> "Drier 2 System Isolations Sequence.ini", _
> "MacroSettings", "CertificateNumber") = CertNo
> End Sub
> Sub SaveCertificateAs()
> CertNo = System.PrivateProfileString(sPath & _
> "Drier 2 System Isolations Sequence.ini", _
> "MacroSettings", "CertificateNumber")
> If Not ActiveDocument.Path = "" Then
>    ActiveDocument.Save
> Else
>    With Dialogs(wdDialogFileSaveAs)
>        .Name = sPath & "Drier 2 System Isolations " _
>        & Format(CertNo, "200#")
>        .Show
>    End With
> End If
> ActiveDocument.Close
> End Sub
>
> Sub AutoClose() 'Recycles number if document unsaved.'
> Set oVars = ActiveDocument.Variables
> CertNo = System.PrivateProfileString(sPath & _
> "Drier 2 System Isolations Sequence.ini", _
> "MacroSettings", "CertificateNumber")
> If Len(ActiveDocument.Path) = 0 Then
>    If MsgBox("This Certificate has not been saved." & vbCr & _
>        "Do you want to save before closing?", _
>        vbYesNo, "MacroSettings") = vbYes Then
>        With Dialogs(wdDialogFileSaveAs)
>            .Name = sPath & "Drier 2 System Isolations " _
>            & Format(CertNo, "200#")
>            .Show
>        End With
>    Else
>        If CertNo = oVars("varCertNo") Then
>            MsgBox "The current number " & _
>            "will be recycled.", vbOKCancel, _
>            "Recycle"
>            System.PrivateProfileString(sPath & _
>            "Drier 2 System Isolations Sequence.ini", _
>            "MacroSettings", "CertificateNumber") = CertNo - 1
>        End If
>    End If
>    ActiveDocument.Saved = True
> End If
> End Sub
>
> Sub ResetStartNo()
> CertNo = System.PrivateProfileString(sPath & _
> "Drier 2 System Isolations Sequence.ini", _
> "MacroSettings", "CertificateNumber")
> CertNo = InputBox("Reset next certificate number?", "Reset", CertNo)
> System.PrivateProfileString(sPath & _
> "Drier 2 System Isolations Sequence.ini", _
> "MacroSettings", "CertificateNumber") = CertNo - 1
> End Sub
>
> Having looked again at the macros, I felt that it might make more sense to 
> the user to insert the number with a docvariable field rather than as 
> plain text. This allows the current document to be updated when the number 
> is reset. It needed a few extra lines of code to ensure that documents 
> displayed and were saved with the right number, but the principles 
> involved are much the same. I am however puzzled why you format the 
> numbers as 200#. Why not simply set the start number as 2001? However I 
> have left it as you had it.
>
> Option Explicit
> Private CertNo As String
> Private oHeader As Range
> Private oHead As HeaderFooter
> Private oField As Field
> Dim oRng As Range
> Private sName As String
> Private oVars As Variables
> Const sPath = "S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems Isolations\"
> Sub AutoNew()
> Set oVars = ActiveDocument.Variables
> CertNo = System.PrivateProfileString(sPath & _
> "Drier 2 System Isolations Sequence.ini", _
> "MacroSettings", "CertificateNumber")
> If CertNo = "" Then
>    CertNo = 1
> Else
>    CertNo = CertNo + 1
> End If
> oVars("varCertNo").Value = CertNo
> oVars("varSaveNo").Value = CertNo
> If ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Exists Then
>    Set oHeader = 
> ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
> Else
>    Set oHeader = 
> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
> End If
> With oHeader
>    .Text = "Certificate No: "
>    .Font.Bold = True 'of the inserted header
>    .Font.Italic = False 'if required
>    .Font.Size = "16"
>    .ParagraphFormat.Alignment = wdAlignParagraphRight
>    .Collapse wdCollapseEnd
>    .Fields.Add oHeader, wdFieldDocVariable, _
>    """varCertNo"" \# ""200#""", False
>    .Fields.Update
> End With
> System.PrivateProfileString(sPath & _
> "Drier 2 System Isolations Sequence.ini", _
> "MacroSettings", "CertificateNumber") = CertNo
> End Sub
> Sub SaveCertificateAs()
> CertNo = System.PrivateProfileString(sPath & _
> "Drier 2 System Isolations Sequence.ini", _
> "MacroSettings", "CertificateNumber")
> If Not ActiveDocument.Path = "" Then
>    ActiveDocument.Save
> Else
>    With Dialogs(wdDialogFileSaveAs)
>        .Name = sPath & "Drier 2 System Isolations 200" _
>        & ActiveDocument.Variables("varSaveNo")
>        .Show
>    End With
> End If
> ActiveDocument.Close
> End Sub
>
> Sub AutoClose() 'Recycles number if document unsaved.'
> Set oVars = ActiveDocument.Variables
> CertNo = System.PrivateProfileString(sPath & _
> "Drier 2 System Isolations Sequence.ini", _
> "MacroSettings", "CertificateNumber")
> If Len(ActiveDocument.Path) = 0 Then
>    If MsgBox("This Certificate has not been saved." & vbCr & _
>        "Do you want to save before closing?", _
>        vbYesNo, "MacroSettings") = vbYes Then
>        With Dialogs(wdDialogFileSaveAs)
>            .Name = sPath & "Drier 2 System Isolations 200" _
>            & oVars("VarSaveNo").Value
>            .Show
>        End With
>    Else
>        If CertNo = oVars("varCertNo") Then
>            MsgBox "The current number " & _
>            "will be recycled.", vbOKCancel, _
>            "Recycle"
>            System.PrivateProfileString(sPath & _
>            "Drier 2 System Isolations Sequence.ini", _
>            "MacroSettings", "CertificateNumber") = CertNo - 1
>        End If
>    End If
>    ActiveDocument.Saved = True
> End If
> End Sub
>
> Sub ResetStartNo()
> Set oVars = ActiveDocument.Variables
>
> CertNo = System.PrivateProfileString(sPath & _
> "Drier 2 System Isolations Sequence.ini", _
> "MacroSettings", "CertificateNumber")
>
> CertNo = InputBox("Reset next certificate number?", _
> "Reset", CertNo)
>
> oVars("varSaveNo").Value = CertNo
>
> System.PrivateProfileString(sPath & _
> "Drier 2 System Isolations Sequence.ini", _
> "MacroSettings", "CertificateNumber") = CertNo
>
> oVars("varCertNo").Value = CertNo
>
> For Each oHead In ActiveDocument.Sections(1).Headers
>    If oHead.Exists Then
>        For Each oField In oHead.Range.Fields
>            oField.Update
>        Next oField
>    End If
> Next oHead
> End Sub
>
>
> -- 
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor -  Word MVP
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
>
> "rachgg4" <rachgg4@discussions.microsoft.com> wrote in message 
> news:A9165EE7-AA80-4608-AD66-9BD8FCB6A49F@microsoft.com...
>>I am so grateful for all the help.
>> This is absolutely brilliant!!
>> Only one thing that won't work properly is the recycling of the number. 
>> It
>> will ask if I want to save changes and I choose 'no' then asks 'Do I want 
>> to
>> recycle the number? (e.g 2001) and I say 'yes' but when the doc template 
>> is
>> opened for the next document to be generated, it has the next number as
>> '2002' not '2001'. Have I missed something yet again?
>> Sorry if I am not quite getting it.
>> Thanks in advance
>> rachgg4
>>
>> "Graham Mayor" wrote:
>>
>>> You need to save the 'document' as a template and create new documents 
>>> from
>>> it, using an autonew macro to apply the number.
>>>
>>> If your macro writes the next number to the ini file (which needs to be 
>>> in a
>>> location anyone using the template can access) then if the document is
>>> closed without saving, you need an autoclose macro to decrement the 
>>> stored
>>> number to enable the number to be re-used. It is not possible for the 
>>> macro
>>> to second guess whether the user intended to keep a saved number or not. 
>>> As
>>> someone will inevitably screw it up, you need a macro to reset the start
>>> number.
>>>
>>> Create a new module in the template -
>>> http://www.gmayor.com/installing_macro.htm and try the following, which
>>> seems to do what your macros attempted to do.
>>>
>>> Option Explicit
>>> Private CertNo As String
>>> Private oHeader As Range
>>> Private sName As String
>>> Const sPath = "S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems 
>>> Isolations\"
>>> Sub AutoNew()
>>> CertNo = System.PrivateProfileString(sPath & _
>>> "Drier 2 System Isolations Sequence.ini", _
>>> "MacroSettings", "CertificateNumber")
>>> If CertNo = "" Then
>>>     CertNo = 1
>>> Else
>>>     CertNo = CertNo + 1
>>> End If
>>> If ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Exists 
>>> Then
>>>     Set oHeader =
>>> ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
>>> Else
>>>     Set oHeader =
>>> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
>>> End If
>>> With oHeader
>>>     .Text = "Certificate No: " & Format(CertNo, "200#")
>>>     .Font.Bold = True 'of the inserted header
>>>     .Font.Italic = False 'if required
>>>     .Font.Size = "16"
>>>     .ParagraphFormat.Alignment = wdAlignParagraphRight
>>> End With
>>> System.PrivateProfileString(sPath & _
>>> "Drier 2 System Isolations Sequence.ini", _
>>> "MacroSettings", "CertificateNumber") = CertNo
>>> End Sub
>>> Sub SaveCertificateAs()
>>> CertNo = System.PrivateProfileString(sPath & _
>>> "Drier 2 System Isolations Sequence.ini", _
>>> "MacroSettings", "CertificateNumber")
>>> If Not ActiveDocument.Path = "" Then
>>>     ActiveDocument.Save
>>> Else
>>>     With Dialogs(wdDialogFileSaveAs)
>>>         .Name = sPath & "Drier 2 System Isolations " _
>>>         & Format(CertNo, "200#")
>>>         .Show
>>>     End With
>>> End If
>>> ActiveDocument.Close
>>> End Sub
>>>
>>> Sub AutoClose() 'Recycles number if document unsaved.'
>>> CertNo = System.PrivateProfileString(sPath & _
>>> "Drier 2 System Isolations Sequence.ini", _
>>> "MacroSettings", "CertificateNumber")
>>> If Len(ActiveDocument.Path) = 0 Then
>>>     If MsgBox("This Certificate has not been saved." & vbCr & _
>>>         "Do you want to save before closing?", _
>>>         vbYesNo, "MacroSettings") = vbYes Then
>>>         With Dialogs(wdDialogFileSaveAs)
>>>             .Name = sPath & "Drier 2 System Isolations " _
>>>             & Format(CertNo, "200#")
>>>             .Show
>>>         End With
>>>     Else
>>>         MsgBox "The current number " & _
>>>         "will be recycled.", vbOKCancel, _
>>>         "Recycle"
>>>     End If
>>>     ActiveDocument.Saved = True
>>> End If
>>> End Sub
>>>
>>> Sub ResetStartNo()
>>> CertNo = System.PrivateProfileString(sPath & _
>>> "Drier 2 System Isolations Sequence.ini", _
>>> "MacroSettings", "CertificateNumber")
>>> CertNo = InputBox("Reset next certificate number?", "Reset", CertNo)
>>> System.PrivateProfileString(sPath & _
>>> "Drier 2 System Isolations Sequence.ini", _
>>> "MacroSettings", "CertificateNumber") = CertNo - 1
>>> End Sub
>>>
>>>
>>>
>>>
>>> "rachgg4" <rachgg4@discussions.microsoft.com> wrote in message
>>> news:28C57B35-CDFF-4218-B0B4-C6EDB901857A@microsoft.com...
>>> > 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
>>> >
>>> >
>>> >
>>> > "Doug Robbins - Word MVP" wrote:
>>> >
>>> >> The easiest way for you to do that is go to the File>Properties 
>>> >> dialog
>>> >> and
>>> >> then go to the Custom tab and in the Name: field, type DocNumber and 
>>> >> in
>>> >> the
>>> >> Value: field, type the starting number that you wish to use e.g. 1, 
>>> >> then
>>> >> click on Add, then click on OK.
>>> >>
>>> >> Then in your document, and in the location where you want the number 
>>> >> to
>>> >> appear, go to the Insert>Field dialog and scroll down through the 
>>> >> list of
>>> >> fields to the DocProperty field and then in the list of properties,
>>> >> select
>>> >> the DocNumber item from the list.  When you click OK, the starting 
>>> >> number
>>> >> that you entered will appear in the document.
>>> >>
>>> >> To get this number to be updated each time the document is opened, 
>>> >> create
>>> >> the following macro
>>> >>
>>> >> Sub AutoOpen()
>>> >> On Error GoTo EndThis  'Exits the routine if the Custom Document 
>>> >> Property
>>> >> DocNumber has not be added to the document
>>> >> With ActiveDocument
>>> >>     .CustomDocumentProperties("DocNumber") =
>>> >> ..CustomDocumentProperties("DocNumber") + 1
>>> >>     .Range.Fields.Update
>>> >> End With
>>> >>
>>> >> EndThis:
>>> >>
>>> >> End Sub
>
> 


0
Graham
1/24/2010 8:35:59 AM
I have now revised the code on my web page 
http://www.gmayor.com/automatic_numbering_documents.htm to reflect the code 
shown here (albeit without your personal settings). The code is fully 
annotated so that you can see how it works.

-- 
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


"Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message 
news:OERyBBNnKHA.2544@TK2MSFTNGP04.phx.gbl...
>I have just spotted another glitch :(
>
> Change both instances of
>
> With Dialogs(wdDialogFileSaveAs)
>        .Name = sPath & "Drier 2 System Isolations " _
>        & Format(CertNo, "200#")
>        .Show
> End With
>
> to
>
> With Dialogs(wdDialogFileSaveAs)
>            .Name = sPath & "Drier 2 System Isolations " _
>            & Format(ActiveDocument.Variables("varSaveNo"), "200#")
>            .Show
> End With
>
>
> -- 
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor -  Word MVP
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
>
> "Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message 
> news:uCTqQxMnKHA.5520@TK2MSFTNGP05.phx.gbl...
>> Oops! My fault. The following version should fix the renumbering issues. 
>> Do note however that when inserting the number as plain text (as in this 
>> instance) you cannot change the number of the current document. (see 
>> later)
>>
>>
>> Option Explicit
>> Private CertNo As String
>> Private oHeader As Range
>> Private sName As String
>> Private oVars As Variables
>> Const sPath = "S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems Isolations\"
>> Sub AutoNew()
>> Set oVars = ActiveDocument.Variables
>> CertNo = System.PrivateProfileString(sPath & _
>> "Drier 2 System Isolations Sequence.ini", _
>> "MacroSettings", "CertificateNumber")
>> If CertNo = "" Then
>>    CertNo = 1
>> Else
>>    CertNo = CertNo + 1
>> End If
>> oVars("varCertNo").Value = CertNo
>> If ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Exists 
>> Then
>>    Set oHeader = 
>> ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
>> Else
>>    Set oHeader = 
>> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
>> End If
>> With oHeader
>>    .Text = "Certificate No: " & Format(CertNo, "200#")
>>    .Font.Bold = True 'of the inserted header
>>    .Font.Italic = False 'if required
>>    .Font.Size = "16"
>>    .ParagraphFormat.Alignment = wdAlignParagraphRight
>> End With
>> System.PrivateProfileString(sPath & _
>> "Drier 2 System Isolations Sequence.ini", _
>> "MacroSettings", "CertificateNumber") = CertNo
>> End Sub
>> Sub SaveCertificateAs()
>> CertNo = System.PrivateProfileString(sPath & _
>> "Drier 2 System Isolations Sequence.ini", _
>> "MacroSettings", "CertificateNumber")
>> If Not ActiveDocument.Path = "" Then
>>    ActiveDocument.Save
>> Else
>>    With Dialogs(wdDialogFileSaveAs)
>>        .Name = sPath & "Drier 2 System Isolations " _
>>        & Format(CertNo, "200#")
>>        .Show
>>    End With
>> End If
>> ActiveDocument.Close
>> End Sub
>>
>> Sub AutoClose() 'Recycles number if document unsaved.'
>> Set oVars = ActiveDocument.Variables
>> CertNo = System.PrivateProfileString(sPath & _
>> "Drier 2 System Isolations Sequence.ini", _
>> "MacroSettings", "CertificateNumber")
>> If Len(ActiveDocument.Path) = 0 Then
>>    If MsgBox("This Certificate has not been saved." & vbCr & _
>>        "Do you want to save before closing?", _
>>        vbYesNo, "MacroSettings") = vbYes Then
>>        With Dialogs(wdDialogFileSaveAs)
>>            .Name = sPath & "Drier 2 System Isolations " _
>>            & Format(CertNo, "200#")
>>            .Show
>>        End With
>>    Else
>>        If CertNo = oVars("varCertNo") Then
>>            MsgBox "The current number " & _
>>            "will be recycled.", vbOKCancel, _
>>            "Recycle"
>>            System.PrivateProfileString(sPath & _
>>            "Drier 2 System Isolations Sequence.ini", _
>>            "MacroSettings", "CertificateNumber") = CertNo - 1
>>        End If
>>    End If
>>    ActiveDocument.Saved = True
>> End If
>> End Sub
>>
>> Sub ResetStartNo()
>> CertNo = System.PrivateProfileString(sPath & _
>> "Drier 2 System Isolations Sequence.ini", _
>> "MacroSettings", "CertificateNumber")
>> CertNo = InputBox("Reset next certificate number?", "Reset", CertNo)
>> System.PrivateProfileString(sPath & _
>> "Drier 2 System Isolations Sequence.ini", _
>> "MacroSettings", "CertificateNumber") = CertNo - 1
>> End Sub
>>
>> Having looked again at the macros, I felt that it might make more sense 
>> to the user to insert the number with a docvariable field rather than as 
>> plain text. This allows the current document to be updated when the 
>> number is reset. It needed a few extra lines of code to ensure that 
>> documents displayed and were saved with the right number, but the 
>> principles involved are much the same. I am however puzzled why you 
>> format the numbers as 200#. Why not simply set the start number as 2001? 
>> However I have left it as you had it.
>>
>> Option Explicit
>> Private CertNo As String
>> Private oHeader As Range
>> Private oHead As HeaderFooter
>> Private oField As Field
>> Dim oRng As Range
>> Private sName As String
>> Private oVars As Variables
>> Const sPath = "S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems Isolations\"
>> Sub AutoNew()
>> Set oVars = ActiveDocument.Variables
>> CertNo = System.PrivateProfileString(sPath & _
>> "Drier 2 System Isolations Sequence.ini", _
>> "MacroSettings", "CertificateNumber")
>> If CertNo = "" Then
>>    CertNo = 1
>> Else
>>    CertNo = CertNo + 1
>> End If
>> oVars("varCertNo").Value = CertNo
>> oVars("varSaveNo").Value = CertNo
>> If ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Exists 
>> Then
>>    Set oHeader = 
>> ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
>> Else
>>    Set oHeader = 
>> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
>> End If
>> With oHeader
>>    .Text = "Certificate No: "
>>    .Font.Bold = True 'of the inserted header
>>    .Font.Italic = False 'if required
>>    .Font.Size = "16"
>>    .ParagraphFormat.Alignment = wdAlignParagraphRight
>>    .Collapse wdCollapseEnd
>>    .Fields.Add oHeader, wdFieldDocVariable, _
>>    """varCertNo"" \# ""200#""", False
>>    .Fields.Update
>> End With
>> System.PrivateProfileString(sPath & _
>> "Drier 2 System Isolations Sequence.ini", _
>> "MacroSettings", "CertificateNumber") = CertNo
>> End Sub
>> Sub SaveCertificateAs()
>> CertNo = System.PrivateProfileString(sPath & _
>> "Drier 2 System Isolations Sequence.ini", _
>> "MacroSettings", "CertificateNumber")
>> If Not ActiveDocument.Path = "" Then
>>    ActiveDocument.Save
>> Else
>>    With Dialogs(wdDialogFileSaveAs)
>>        .Name = sPath & "Drier 2 System Isolations 200" _
>>        & ActiveDocument.Variables("varSaveNo")
>>        .Show
>>    End With
>> End If
>> ActiveDocument.Close
>> End Sub
>>
>> Sub AutoClose() 'Recycles number if document unsaved.'
>> Set oVars = ActiveDocument.Variables
>> CertNo = System.PrivateProfileString(sPath & _
>> "Drier 2 System Isolations Sequence.ini", _
>> "MacroSettings", "CertificateNumber")
>> If Len(ActiveDocument.Path) = 0 Then
>>    If MsgBox("This Certificate has not been saved." & vbCr & _
>>        "Do you want to save before closing?", _
>>        vbYesNo, "MacroSettings") = vbYes Then
>>        With Dialogs(wdDialogFileSaveAs)
>>            .Name = sPath & "Drier 2 System Isolations 200" _
>>            & oVars("VarSaveNo").Value
>>            .Show
>>        End With
>>    Else
>>        If CertNo = oVars("varCertNo") Then
>>            MsgBox "The current number " & _
>>            "will be recycled.", vbOKCancel, _
>>            "Recycle"
>>            System.PrivateProfileString(sPath & _
>>            "Drier 2 System Isolations Sequence.ini", _
>>            "MacroSettings", "CertificateNumber") = CertNo - 1
>>        End If
>>    End If
>>    ActiveDocument.Saved = True
>> End If
>> End Sub
>>
>> Sub ResetStartNo()
>> Set oVars = ActiveDocument.Variables
>>
>> CertNo = System.PrivateProfileString(sPath & _
>> "Drier 2 System Isolations Sequence.ini", _
>> "MacroSettings", "CertificateNumber")
>>
>> CertNo = InputBox("Reset next certificate number?", _
>> "Reset", CertNo)
>>
>> oVars("varSaveNo").Value = CertNo
>>
>> System.PrivateProfileString(sPath & _
>> "Drier 2 System Isolations Sequence.ini", _
>> "MacroSettings", "CertificateNumber") = CertNo
>>
>> oVars("varCertNo").Value = CertNo
>>
>> For Each oHead In ActiveDocument.Sections(1).Headers
>>    If oHead.Exists Then
>>        For Each oField In oHead.Range.Fields
>>            oField.Update
>>        Next oField
>>    End If
>> Next oHead
>> End Sub
>>
>>
>> -- 
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> Graham Mayor -  Word MVP
>>
>> My web site www.gmayor.com
>> Word MVP web site http://word.mvps.org
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>
>>
>> "rachgg4" <rachgg4@discussions.microsoft.com> wrote in message 
>> news:A9165EE7-AA80-4608-AD66-9BD8FCB6A49F@microsoft.com...
>>>I am so grateful for all the help.
>>> This is absolutely brilliant!!
>>> Only one thing that won't work properly is the recycling of the number. 
>>> It
>>> will ask if I want to save changes and I choose 'no' then asks 'Do I 
>>> want to
>>> recycle the number? (e.g 2001) and I say 'yes' but when the doc template 
>>> is
>>> opened for the next document to be generated, it has the next number as
>>> '2002' not '2001'. Have I missed something yet again?
>>> Sorry if I am not quite getting it.
>>> Thanks in advance
>>> rachgg4
>>>
>>> "Graham Mayor" wrote:
>>>
>>>> You need to save the 'document' as a template and create new documents 
>>>> from
>>>> it, using an autonew macro to apply the number.
>>>>
>>>> If your macro writes the next number to the ini file (which needs to be 
>>>> in a
>>>> location anyone using the template can access) then if the document is
>>>> closed without saving, you need an autoclose macro to decrement the 
>>>> stored
>>>> number to enable the number to be re-used. It is not possible for the 
>>>> macro
>>>> to second guess whether the user intended to keep a saved number or 
>>>> not. As
>>>> someone will inevitably screw it up, you need a macro to reset the 
>>>> start
>>>> number.
>>>>
>>>> Create a new module in the template -
>>>> http://www.gmayor.com/installing_macro.htm and try the following, which
>>>> seems to do what your macros attempted to do.
>>>>
>>>> Option Explicit
>>>> Private CertNo As String
>>>> Private oHeader As Range
>>>> Private sName As String
>>>> Const sPath = "S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems 
>>>> Isolations\"
>>>> Sub AutoNew()
>>>> CertNo = System.PrivateProfileString(sPath & _
>>>> "Drier 2 System Isolations Sequence.ini", _
>>>> "MacroSettings", "CertificateNumber")
>>>> If CertNo = "" Then
>>>>     CertNo = 1
>>>> Else
>>>>     CertNo = CertNo + 1
>>>> End If
>>>> If ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Exists 
>>>> Then
>>>>     Set oHeader =
>>>> ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
>>>> Else
>>>>     Set oHeader =
>>>> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
>>>> End If
>>>> With oHeader
>>>>     .Text = "Certificate No: " & Format(CertNo, "200#")
>>>>     .Font.Bold = True 'of the inserted header
>>>>     .Font.Italic = False 'if required
>>>>     .Font.Size = "16"
>>>>     .ParagraphFormat.Alignment = wdAlignParagraphRight
>>>> End With
>>>> System.PrivateProfileString(sPath & _
>>>> "Drier 2 System Isolations Sequence.ini", _
>>>> "MacroSettings", "CertificateNumber") = CertNo
>>>> End Sub
>>>> Sub SaveCertificateAs()
>>>> CertNo = System.PrivateProfileString(sPath & _
>>>> "Drier 2 System Isolations Sequence.ini", _
>>>> "MacroSettings", "CertificateNumber")
>>>> If Not ActiveDocument.Path = "" Then
>>>>     ActiveDocument.Save
>>>> Else
>>>>     With Dialogs(wdDialogFileSaveAs)
>>>>         .Name = sPath & "Drier 2 System Isolations " _
>>>>         & Format(CertNo, "200#")
>>>>         .Show
>>>>     End With
>>>> End If
>>>> ActiveDocument.Close
>>>> End Sub
>>>>
>>>> Sub AutoClose() 'Recycles number if document unsaved.'
>>>> CertNo = System.PrivateProfileString(sPath & _
>>>> "Drier 2 System Isolations Sequence.ini", _
>>>> "MacroSettings", "CertificateNumber")
>>>> If Len(ActiveDocument.Path) = 0 Then
>>>>     If MsgBox("This Certificate has not been saved." & vbCr & _
>>>>         "Do you want to save before closing?", _
>>>>         vbYesNo, "MacroSettings") = vbYes Then
>>>>         With Dialogs(wdDialogFileSaveAs)
>>>>             .Name = sPath & "Drier 2 System Isolations " _
>>>>             & Format(CertNo, "200#")
>>>>             .Show
>>>>         End With
>>>>     Else
>>>>         MsgBox "The current number " & _
>>>>         "will be recycled.", vbOKCancel, _
>>>>         "Recycle"
>>>>     End If
>>>>     ActiveDocument.Saved = True
>>>> End If
>>>> End Sub
>>>>
>>>> Sub ResetStartNo()
>>>> CertNo = System.PrivateProfileString(sPath & _
>>>> "Drier 2 System Isolations Sequence.ini", _
>>>> "MacroSettings", "CertificateNumber")
>>>> CertNo = InputBox("Reset next certificate number?", "Reset", CertNo)
>>>> System.PrivateProfileString(sPath & _
>>>> "Drier 2 System Isolations Sequence.ini", _
>>>> "MacroSettings", "CertificateNumber") = CertNo - 1
>>>> End Sub
>>>>
>>>>
>>>>
>>>>
>>>> "rachgg4" <rachgg4@discussions.microsoft.com> wrote in message
>>>> news:28C57B35-CDFF-4218-B0B4-C6EDB901857A@microsoft.com...
>>>> > 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
>>>> >
>>>> >
>>>> >
>>>> > "Doug Robbins - Word MVP" wrote:
>>>> >
>>>> >> The easiest way for you to do that is go to the File>Properties 
>>>> >> dialog
>>>> >> and
>>>> >> then go to the Custom tab and in the Name: field, type DocNumber and 
>>>> >> in
>>>> >> the
>>>> >> Value: field, type the starting number that you wish to use e.g. 1, 
>>>> >> then
>>>> >> click on Add, then click on OK.
>>>> >>
>>>> >> Then in your document, and in the location where you want the number 
>>>> >> to
>>>> >> appear, go to the Insert>Field dialog and scroll down through the 
>>>> >> list of
>>>> >> fields to the DocProperty field and then in the list of properties,
>>>> >> select
>>>> >> the DocNumber item from the list.  When you click OK, the starting 
>>>> >> number
>>>> >> that you entered will appear in the document.
>>>> >>
>>>> >> To get this number to be updated each time the document is opened, 
>>>> >> create
>>>> >> the following macro
>>>> >>
>>>> >> Sub AutoOpen()
>>>> >> On Error GoTo EndThis  'Exits the routine if the Custom Document 
>>>> >> Property
>>>> >> DocNumber has not be added to the document
>>>> >> With ActiveDocument
>>>> >>     .CustomDocumentProperties("DocNumber") =
>>>> >> ..CustomDocumentProperties("DocNumber") + 1
>>>> >>     .Range.Fields.Update
>>>> >> End With
>>>> >>
>>>> >> EndThis:
>>>> >>
>>>> >> End Sub
>>
>>
>
> 


0
Graham
1/24/2010 10:52:41 AM
It worked!!!!! :) :) 
Thank you so much.
I did have to 'tweak' the code so it didn't double up on the wording in the 
header, but other than that, it was absolutely brilliant!
I couldn't have done this without your help and expertise. All the time and 
effort you have provided is so appreciated and I'm sure other forum users 
will find this such a help.
Many thanks,
rachgg4

"Graham Mayor" wrote:

> I have now revised the code on my web page 
> http://www.gmayor.com/automatic_numbering_documents.htm to reflect the code 
> shown here (albeit without your personal settings). The code is fully 
> annotated so that you can see how it works.
> 
> -- 
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor -  Word MVP
> 
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> 
> 
> "Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message 
> news:OERyBBNnKHA.2544@TK2MSFTNGP04.phx.gbl...
> >I have just spotted another glitch :(
> >
> > Change both instances of
> >
> > With Dialogs(wdDialogFileSaveAs)
> >        .Name = sPath & "Drier 2 System Isolations " _
> >        & Format(CertNo, "200#")
> >        .Show
> > End With
> >
> > to
> >
> > With Dialogs(wdDialogFileSaveAs)
> >            .Name = sPath & "Drier 2 System Isolations " _
> >            & Format(ActiveDocument.Variables("varSaveNo"), "200#")
> >            .Show
> > End With
> >
> >
> > -- 
> > <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> > Graham Mayor -  Word MVP
> >
> > My web site www.gmayor.com
> > Word MVP web site http://word.mvps.org
> > <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> >
> >
> > "Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message 
> > news:uCTqQxMnKHA.5520@TK2MSFTNGP05.phx.gbl...
> >> Oops! My fault. The following version should fix the renumbering issues. 
> >> Do note however that when inserting the number as plain text (as in this 
> >> instance) you cannot change the number of the current document. (see 
> >> later)
> >>
> >>
> >> Option Explicit
> >> Private CertNo As String
> >> Private oHeader As Range
> >> Private sName As String
> >> Private oVars As Variables
> >> Const sPath = "S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems Isolations\"
> >> Sub AutoNew()
> >> Set oVars = ActiveDocument.Variables
> >> CertNo = System.PrivateProfileString(sPath & _
> >> "Drier 2 System Isolations Sequence.ini", _
> >> "MacroSettings", "CertificateNumber")
> >> If CertNo = "" Then
> >>    CertNo = 1
> >> Else
> >>    CertNo = CertNo + 1
> >> End If
> >> oVars("varCertNo").Value = CertNo
> >> If ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Exists 
> >> Then
> >>    Set oHeader = 
> >> ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
> >> Else
> >>    Set oHeader = 
> >> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
> >> End If
> >> With oHeader
> >>    .Text = "Certificate No: " & Format(CertNo, "200#")
> >>    .Font.Bold = True 'of the inserted header
> >>    .Font.Italic = False 'if required
> >>    .Font.Size = "16"
> >>    .ParagraphFormat.Alignment = wdAlignParagraphRight
> >> End With
> >> System.PrivateProfileString(sPath & _
> >> "Drier 2 System Isolations Sequence.ini", _
> >> "MacroSettings", "CertificateNumber") = CertNo
> >> End Sub
> >> Sub SaveCertificateAs()
> >> CertNo = System.PrivateProfileString(sPath & _
> >> "Drier 2 System Isolations Sequence.ini", _
> >> "MacroSettings", "CertificateNumber")
> >> If Not ActiveDocument.Path = "" Then
> >>    ActiveDocument.Save
> >> Else
> >>    With Dialogs(wdDialogFileSaveAs)
> >>        .Name = sPath & "Drier 2 System Isolations " _
> >>        & Format(CertNo, "200#")
> >>        .Show
> >>    End With
> >> End If
> >> ActiveDocument.Close
> >> End Sub
> >>
> >> Sub AutoClose() 'Recycles number if document unsaved.'
> >> Set oVars = ActiveDocument.Variables
> >> CertNo = System.PrivateProfileString(sPath & _
> >> "Drier 2 System Isolations Sequence.ini", _
> >> "MacroSettings", "CertificateNumber")
> >> If Len(ActiveDocument.Path) = 0 Then
> >>    If MsgBox("This Certificate has not been saved." & vbCr & _
> >>        "Do you want to save before closing?", _
> >>        vbYesNo, "MacroSettings") = vbYes Then
> >>        With Dialogs(wdDialogFileSaveAs)
> >>            .Name = sPath & "Drier 2 System Isolations " _
> >>            & Format(CertNo, "200#")
> >>            .Show
> >>        End With
> >>    Else
> >>        If CertNo = oVars("varCertNo") Then
> >>            MsgBox "The current number " & _
> >>            "will be recycled.", vbOKCancel, _
> >>            "Recycle"
> >>            System.PrivateProfileString(sPath & _
> >>            "Drier 2 System Isolations Sequence.ini", _
> >>            "MacroSettings", "CertificateNumber") = CertNo - 1
> >>        End If
> >>    End If
> >>    ActiveDocument.Saved = True
> >> End If
> >> End Sub
> >>
> >> Sub ResetStartNo()
> >> CertNo = System.PrivateProfileString(sPath & _
> >> "Drier 2 System Isolations Sequence.ini", _
> >> "MacroSettings", "CertificateNumber")
> >> CertNo = InputBox("Reset next certificate number?", "Reset", CertNo)
> >> System.PrivateProfileString(sPath & _
> >> "Drier 2 System Isolations Sequence.ini", _
> >> "MacroSettings", "CertificateNumber") = CertNo - 1
> >> End Sub
> >>
> >> Having looked again at the macros, I felt that it might make more sense 
> >> to the user to insert the number with a docvariable field rather than as 
> >> plain text. This allows the current document to be updated when the 
> >> number is reset. It needed a few extra lines of code to ensure that 
> >> documents displayed and were saved with the right number, but the 
> >> principles involved are much the same. I am however puzzled why you 
> >> format the numbers as 200#. Why not simply set the start number as 2001? 
> >> However I have left it as you had it.
> >>
> >> Option Explicit
> >> Private CertNo As String
> >> Private oHeader As Range
> >> Private oHead As HeaderFooter
> >> Private oField As Field
> >> Dim oRng As Range
> >> Private sName As String
> >> Private oVars As Variables
> >> Const sPath = "S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems Isolations\"
> >> Sub AutoNew()
> >> Set oVars = ActiveDocument.Variables
> >> CertNo = System.PrivateProfileString(sPath & _
> >> "Drier 2 System Isolations Sequence.ini", _
> >> "MacroSettings", "CertificateNumber")
> >> If CertNo = "" Then
> >>    CertNo = 1
> >> Else
> >>    CertNo = CertNo + 1
> >> End If
> >> oVars("varCertNo").Value = CertNo
> >> oVars("varSaveNo").Value = CertNo
> >> If ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Exists 
> >> Then
> >>    Set oHeader = 
> >> ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
> >> Else
> >>    Set oHeader = 
> >> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
> >> End If
> >> With oHeader
> >>    .Text = "Certificate No: "
> >>    .Font.Bold = True 'of the inserted header
> >>    .Font.Italic = False 'if required
> >>    .Font.Size = "16"
> >>    .ParagraphFormat.Alignment = wdAlignParagraphRight
> >>    .Collapse wdCollapseEnd
> >>    .Fields.Add oHeader, wdFieldDocVariable, _
> >>    """varCertNo"" \# ""200#""", False
> >>    .Fields.Update
> >> End With
> >> System.PrivateProfileString(sPath & _
> >> "Drier 2 System Isolations Sequence.ini", _
> >> "MacroSettings", "CertificateNumber") = CertNo
> >> End Sub
> >> Sub SaveCertificateAs()
> >> CertNo = System.PrivateProfileString(sPath & _
> >> "Drier 2 System Isolations Sequence.ini", _
> >> "MacroSettings", "CertificateNumber")
> >> If Not ActiveDocument.Path = "" Then
> >>    ActiveDocument.Save
> >> Else
> >>    With Dialogs(wdDialogFileSaveAs)
> >>        .Name = sPath & "Drier 2 System Isolations 200" _
> >>        & ActiveDocument.Variables("varSaveNo")
> >>        .Show
> >>    End With
> >> End If
> >> ActiveDocument.Close
> >> End Sub
> >>
> >> Sub AutoClose() 'Recycles number if document unsaved.'
> >> Set oVars = ActiveDocument.Variables
> >> CertNo = System.PrivateProfileString(sPath & _
> >> "Drier 2 System Isolations Sequence.ini", _
> >> "MacroSettings", "CertificateNumber")
> >> If Len(ActiveDocument.Path) = 0 Then
> >>    If MsgBox("This Certificate has not been saved." & vbCr & _
> >>        "Do you want to save before closing?", _
> >>        vbYesNo, "MacroSettings") = vbYes Then
> >>        With Dialogs(wdDialogFileSaveAs)
> >>            .Name = sPath & "Drier 2 System Isolations 200" _
> >>            & oVars("VarSaveNo").Value
> >>            .Show
> >>        End With
> >>    Else
> >>        If CertNo = oVars("varCertNo") Then
> >>            MsgBox "The current number " & _
> >>            "will be recycled.", vbOKCancel, _
> >>            "Recycle"
> >>            System.PrivateProfileString(sPath & _
> >>            "Drier 2 System Isolations Sequence.ini", _
> >>            "MacroSettings", "CertificateNumber") = CertNo - 1
> >>        End If
> >>    End If
> >>    ActiveDocument.Saved = True
> >> End If
> >> End Sub
> >>
> >> Sub ResetStartNo()
> >> Set oVars = ActiveDocument.Variables
> >>
> >> CertNo = System.PrivateProfileString(sPath & _
> >> "Drier 2 System Isolations Sequence.ini", _
> >> "MacroSettings", "CertificateNumber")
> >>
> >> CertNo = InputBox("Reset next certificate number?", _
> >> "Reset", CertNo)
> >>
> >> oVars("varSaveNo").Value = CertNo
> >>
> >> System.PrivateProfileString(sPath & _
> >> "Drier 2 System Isolations Sequence.ini", _
> >> "MacroSettings", "CertificateNumber") = CertNo
> >>
> >> oVars("varCertNo").Value = CertNo
> >>
> >> For Each oHead In ActiveDocument.Sections(1).Headers
> >>    If oHead.Exists Then
> >>        For Each oField In oHead.Range.Fields
> >>            oField.Update
> >>        Next oField
> >>    End If
> >> Next oHead
> >> End Sub
> >>
> >>
> >> -- 
> >> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> >> Graham Mayor -  Word MVP
> >>
> >> My web site www.gmayor.com
> >> Word MVP web site http://word.mvps.org
> >> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> >>
> >>
> >> "rachgg4" <rachgg4@discussions.microsoft.com> wrote in message 
> >> news:A9165EE7-AA80-4608-AD66-9BD8FCB6A49F@microsoft.com...
> >>>I am so grateful for all the help.
> >>> This is absolutely brilliant!!
> >>> Only one thing that won't work properly is the recycling of the number. 
> >>> It
> >>> will ask if I want to save changes and I choose 'no' then asks 'Do I 
> >>> want to
> >>> recycle the number? (e.g 2001) and I say 'yes' but when the doc template 
> >>> is
> >>> opened for the next document to be generated, it has the next number as
> >>> '2002' not '2001'. Have I missed something yet again?
> >>> Sorry if I am not quite getting it.
> >>> Thanks in advance
> >>> rachgg4
> >>>
> >>> "Graham Mayor" wrote:
> >>>
> >>>> You need to save the 'document' as a template and create new documents 
> >>>> from
> >>>> it, using an autonew macro to apply the number.
> >>>>
> >>>> If your macro writes the next number to the ini file (which needs to be 
> >>>> in a
0
Utf
1/25/2010 12:47:01 AM
 You are welcome :)

-- 
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


"rachgg4" <rachgg4@discussions.microsoft.com> wrote in message 
news:51C72A05-D7F2-418D-B771-23762732E2BF@microsoft.com...
> It worked!!!!! :) :)
> Thank you so much.
> I did have to 'tweak' the code so it didn't double up on the wording in 
> the
> header, but other than that, it was absolutely brilliant!
> I couldn't have done this without your help and expertise. All the time 
> and
> effort you have provided is so appreciated and I'm sure other forum users
> will find this such a help.
> Many thanks,
> rachgg4
>
> "Graham Mayor" wrote:
>
>> I have now revised the code on my web page
>> http://www.gmayor.com/automatic_numbering_documents.htm to reflect the 
>> code
>> shown here (albeit without your personal settings). The code is fully
>> annotated so that you can see how it works.
>>
>> -- 
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> Graham Mayor -  Word MVP
>>
>> My web site www.gmayor.com
>> Word MVP web site http://word.mvps.org
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>
>>
>> "Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message
>> news:OERyBBNnKHA.2544@TK2MSFTNGP04.phx.gbl...
>> >I have just spotted another glitch :(
>> >
>> > Change both instances of
>> >
>> > With Dialogs(wdDialogFileSaveAs)
>> >        .Name = sPath & "Drier 2 System Isolations " _
>> >        & Format(CertNo, "200#")
>> >        .Show
>> > End With
>> >
>> > to
>> >
>> > With Dialogs(wdDialogFileSaveAs)
>> >            .Name = sPath & "Drier 2 System Isolations " _
>> >            & Format(ActiveDocument.Variables("varSaveNo"), "200#")
>> >            .Show
>> > End With
>> >
>> >
>> > -- 
>> > <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> > Graham Mayor -  Word MVP
>> >
>> > My web site www.gmayor.com
>> > Word MVP web site http://word.mvps.org
>> > <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> >
>> >
>> > "Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message
>> > news:uCTqQxMnKHA.5520@TK2MSFTNGP05.phx.gbl...
>> >> Oops! My fault. The following version should fix the renumbering 
>> >> issues.
>> >> Do note however that when inserting the number as plain text (as in 
>> >> this
>> >> instance) you cannot change the number of the current document. (see
>> >> later)
>> >>
>> >>
>> >> Option Explicit
>> >> Private CertNo As String
>> >> Private oHeader As Range
>> >> Private sName As String
>> >> Private oVars As Variables
>> >> Const sPath = "S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems 
>> >> Isolations\"
>> >> Sub AutoNew()
>> >> Set oVars = ActiveDocument.Variables
>> >> CertNo = System.PrivateProfileString(sPath & _
>> >> "Drier 2 System Isolations Sequence.ini", _
>> >> "MacroSettings", "CertificateNumber")
>> >> If CertNo = "" Then
>> >>    CertNo = 1
>> >> Else
>> >>    CertNo = CertNo + 1
>> >> End If
>> >> oVars("varCertNo").Value = CertNo
>> >> If ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Exists
>> >> Then
>> >>    Set oHeader =
>> >> ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
>> >> Else
>> >>    Set oHeader =
>> >> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
>> >> End If
>> >> With oHeader
>> >>    .Text = "Certificate No: " & Format(CertNo, "200#")
>> >>    .Font.Bold = True 'of the inserted header
>> >>    .Font.Italic = False 'if required
>> >>    .Font.Size = "16"
>> >>    .ParagraphFormat.Alignment = wdAlignParagraphRight
>> >> End With
>> >> System.PrivateProfileString(sPath & _
>> >> "Drier 2 System Isolations Sequence.ini", _
>> >> "MacroSettings", "CertificateNumber") = CertNo
>> >> End Sub
>> >> Sub SaveCertificateAs()
>> >> CertNo = System.PrivateProfileString(sPath & _
>> >> "Drier 2 System Isolations Sequence.ini", _
>> >> "MacroSettings", "CertificateNumber")
>> >> If Not ActiveDocument.Path = "" Then
>> >>    ActiveDocument.Save
>> >> Else
>> >>    With Dialogs(wdDialogFileSaveAs)
>> >>        .Name = sPath & "Drier 2 System Isolations " _
>> >>        & Format(CertNo, "200#")
>> >>        .Show
>> >>    End With
>> >> End If
>> >> ActiveDocument.Close
>> >> End Sub
>> >>
>> >> Sub AutoClose() 'Recycles number if document unsaved.'
>> >> Set oVars = ActiveDocument.Variables
>> >> CertNo = System.PrivateProfileString(sPath & _
>> >> "Drier 2 System Isolations Sequence.ini", _
>> >> "MacroSettings", "CertificateNumber")
>> >> If Len(ActiveDocument.Path) = 0 Then
>> >>    If MsgBox("This Certificate has not been saved." & vbCr & _
>> >>        "Do you want to save before closing?", _
>> >>        vbYesNo, "MacroSettings") = vbYes Then
>> >>        With Dialogs(wdDialogFileSaveAs)
>> >>            .Name = sPath & "Drier 2 System Isolations " _
>> >>            & Format(CertNo, "200#")
>> >>            .Show
>> >>        End With
>> >>    Else
>> >>        If CertNo = oVars("varCertNo") Then
>> >>            MsgBox "The current number " & _
>> >>            "will be recycled.", vbOKCancel, _
>> >>            "Recycle"
>> >>            System.PrivateProfileString(sPath & _
>> >>            "Drier 2 System Isolations Sequence.ini", _
>> >>            "MacroSettings", "CertificateNumber") = CertNo - 1
>> >>        End If
>> >>    End If
>> >>    ActiveDocument.Saved = True
>> >> End If
>> >> End Sub
>> >>
>> >> Sub ResetStartNo()
>> >> CertNo = System.PrivateProfileString(sPath & _
>> >> "Drier 2 System Isolations Sequence.ini", _
>> >> "MacroSettings", "CertificateNumber")
>> >> CertNo = InputBox("Reset next certificate number?", "Reset", CertNo)
>> >> System.PrivateProfileString(sPath & _
>> >> "Drier 2 System Isolations Sequence.ini", _
>> >> "MacroSettings", "CertificateNumber") = CertNo - 1
>> >> End Sub
>> >>
>> >> Having looked again at the macros, I felt that it might make more 
>> >> sense
>> >> to the user to insert the number with a docvariable field rather than 
>> >> as
>> >> plain text. This allows the current document to be updated when the
>> >> number is reset. It needed a few extra lines of code to ensure that
>> >> documents displayed and were saved with the right number, but the
>> >> principles involved are much the same. I am however puzzled why you
>> >> format the numbers as 200#. Why not simply set the start number as 
>> >> 2001?
>> >> However I have left it as you had it.
>> >>
>> >> Option Explicit
>> >> Private CertNo As String
>> >> Private oHeader As Range
>> >> Private oHead As HeaderFooter
>> >> Private oField As Field
>> >> Dim oRng As Range
>> >> Private sName As String
>> >> Private oVars As Variables
>> >> Const sPath = "S:\HLZ1-Hamilton\Morrinsville\MORRINS\Systems 
>> >> Isolations\"
>> >> Sub AutoNew()
>> >> Set oVars = ActiveDocument.Variables
>> >> CertNo = System.PrivateProfileString(sPath & _
>> >> "Drier 2 System Isolations Sequence.ini", _
>> >> "MacroSettings", "CertificateNumber")
>> >> If CertNo = "" Then
>> >>    CertNo = 1
>> >> Else
>> >>    CertNo = CertNo + 1
>> >> End If
>> >> oVars("varCertNo").Value = CertNo
>> >> oVars("varSaveNo").Value = CertNo
>> >> If ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Exists
>> >> Then
>> >>    Set oHeader =
>> >> ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
>> >> Else
>> >>    Set oHeader =
>> >> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
>> >> End If
>> >> With oHeader
>> >>    .Text = "Certificate No: "
>> >>    .Font.Bold = True 'of the inserted header
>> >>    .Font.Italic = False 'if required
>> >>    .Font.Size = "16"
>> >>    .ParagraphFormat.Alignment = wdAlignParagraphRight
>> >>    .Collapse wdCollapseEnd
>> >>    .Fields.Add oHeader, wdFieldDocVariable, _
>> >>    """varCertNo"" \# ""200#""", False
>> >>    .Fields.Update
>> >> End With
>> >> System.PrivateProfileString(sPath & _
>> >> "Drier 2 System Isolations Sequence.ini", _
>> >> "MacroSettings", "CertificateNumber") = CertNo
>> >> End Sub
>> >> Sub SaveCertificateAs()
>> >> CertNo = System.PrivateProfileString(sPath & _
>> >> "Drier 2 System Isolations Sequence.ini", _
>> >> "MacroSettings", "CertificateNumber")
>> >> If Not ActiveDocument.Path = "" Then
>> >>    ActiveDocument.Save
>> >> Else
>> >>    With Dialogs(wdDialogFileSaveAs)
>> >>        .Name = sPath & "Drier 2 System Isolations 200" _
>> >>        & ActiveDocument.Variables("varSaveNo")
>> >>        .Show
>> >>    End With
>> >> End If
>> >> ActiveDocument.Close
>> >> End Sub
>> >>
>> >> Sub AutoClose() 'Recycles number if document unsaved.'
>> >> Set oVars = ActiveDocument.Variables
>> >> CertNo = System.PrivateProfileString(sPath & _
>> >> "Drier 2 System Isolations Sequence.ini", _
>> >> "MacroSettings", "CertificateNumber")
>> >> If Len(ActiveDocument.Path) = 0 Then
>> >>    If MsgBox("This Certificate has not been saved." & vbCr & _
>> >>        "Do you want to save before closing?", _
>> >>        vbYesNo, "MacroSettings") = vbYes Then
>> >>        With Dialogs(wdDialogFileSaveAs)
>> >>            .Name = sPath & "Drier 2 System Isolations 200" _
>> >>            & oVars("VarSaveNo").Value
>> >>            .Show
>> >>        End With
>> >>    Else
>> >>        If CertNo = oVars("varCertNo") Then
>> >>            MsgBox "The current number " & _
>> >>            "will be recycled.", vbOKCancel, _
>> >>            "Recycle"
>> >>            System.PrivateProfileString(sPath & _
>> >>            "Drier 2 System Isolations Sequence.ini", _
>> >>            "MacroSettings", "CertificateNumber") = CertNo - 1
>> >>        End If
>> >>    End If
>> >>    ActiveDocument.Saved = True
>> >> End If
>> >> End Sub
>> >>
>> >> Sub ResetStartNo()
>> >> Set oVars = ActiveDocument.Variables
>> >>
>> >> CertNo = System.PrivateProfileString(sPath & _
>> >> "Drier 2 System Isolations Sequence.ini", _
>> >> "MacroSettings", "CertificateNumber")
>> >>
>> >> CertNo = InputBox("Reset next certificate number?", _
>> >> "Reset", CertNo)
>> >>
>> >> oVars("varSaveNo").Value = CertNo
>> >>
>> >> System.PrivateProfileString(sPath & _
>> >> "Drier 2 System Isolations Sequence.ini", _
>> >> "MacroSettings", "CertificateNumber") = CertNo
>> >>
>> >> oVars("varCertNo").Value = CertNo
>> >>
>> >> For Each oHead In ActiveDocument.Sections(1).Headers
>> >>    If oHead.Exists Then
>> >>        For Each oField In oHead.Range.Fields
>> >>            oField.Update
>> >>        Next oField
>> >>    End If
>> >> Next oHead
>> >> End Sub
>> >>
>> >>
>> >> -- 
>> >> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> >> Graham Mayor -  Word MVP
>> >>
>> >> My web site www.gmayor.com
>> >> Word MVP web site http://word.mvps.org
>> >> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> >>
>> >>
>> >> "rachgg4" <rachgg4@discussions.microsoft.com> wrote in message
>> >> news:A9165EE7-AA80-4608-AD66-9BD8FCB6A49F@microsoft.com...
>> >>>I am so grateful for all the help.
>> >>> This is absolutely brilliant!!
>> >>> Only one thing that won't work properly is the recycling of the 
>> >>> number.
>> >>> It
>> >>> will ask if I want to save changes and I choose 'no' then asks 'Do I
>> >>> want to
>> >>> recycle the number? (e.g 2001) and I say 'yes' but when the doc 
>> >>> template
>> >>> is
>> >>> opened for the next document to be generated, it has the next number 
>> >>> as
>> >>> '2002' not '2001'. Have I missed something yet again?
>> >>> Sorry if I am not quite getting it.
>> >>> Thanks in advance
>> >>> rachgg4
>> >>>
>> >>> "Graham Mayor" wrote:
>> >>>
>> >>>> You need to save the 'document' as a template and create new 
>> >>>> documents
>> >>>> from
>> >>>> it, using an autonew macro to apply the number.
>> >>>>
>> >>>> If your macro writes the next number to the ini file (which needs to 
>> >>>> be
>> >>>> in a 


0
Graham
1/25/2010 6:33:53 AM
Reply:

Similar Artilces:

Difference between two date/time values
Hi, Cell A1 has 21-04-10 07:00 PM Cell A2 has 06-06-10 07:52 AM (the dates are in the dd-mm-yy format) Cell A3 has the formula =A2-A1 for showing the differences in days and time and is formatted with the custom format: dd h:mm:ss The display in cell A3 is 14 12:52:00. While the difference in hours is okay, the difference in days should be more than 14 as there is are 31 days of May between the two dates. Is there another format to show the correct difference in days or should be done some other way? Please help. Thanks in advance. Regards, Raj Do you really need ...

Auto Filter problem
I am using the auto filter for a particular column to sort out differen medical programs. When I click the drop down and click a program, i doesnt show me ALL the lines that say this particular program. Why is this? -- Message posted from http://www.ExcelForum.com Hi maybe some hidden characters in these lines 8e.g. additional space characters, etc.) -- Regards Frank Kabel Frankfurt, Germany "jkb724 >" <<jkb724.19rasx@excelforum-nospam.com> schrieb im Newsbeitrag news:jkb724.19rasx@excelforum-nospam.com... > I am using the auto filter for a particular column to so...

Problem while saving a shared excel'07 document
Hi, in my bussiness, we have a shared excel 2007 document. This document worked fine with Excel 2003, but now we're migrated to 2007, we've got all kind of problems.. When I try to save the document, 6 out of 10 times, the saving failed with an error that Excel could not track changes. You should close the document and try it again, but then you loose all you're changes. You can also turn 'Share Workbook' off, and on again, then you can save the file, but all the changes other people have made are gone... I can't find any solution, so maybe there's...

outlook2003 forwarding (always attaches rather than open)
I have a friend that has the same Outlook 2003 that I do. But when they forward, the email client always attaches the message as an attachment so they can't clean it up prior to forwarding. I can't find the option to make theirs work like mine (which doesn't attach forwarded messages). Thanks!!!! "joe" <bry333@bellsouth.net> wrote in message news:xFc4k.4086$LL4.1727@bignews7.bellsouth.net... >I have a friend that has the same Outlook 2003 that I do. > But when they forward, the email client always attaches the > message as an attachment so they can&#...

Auto-Editing
Word 2003 has a very annoying default. It assumes too much! If I reformat a few words in a document, it changes the entire document to that formatting. Grr-rrr-r! I have to constantly press undo to get what I want. I know there's a feature that's causing this annoyance but I can't find it to turn it off! Can anyone help, please? See http://word.mvps.org/faqs/formatting/wholedocumentreformatted.htm. -- Stefan Blom Microsoft Word MVP "Connie Martin" <ConnieMartin@discussions.microsoft.com> wrote in message news:CD959D82-F81B-4A9D-993E-73...

Date/Time criteria problem
I am trying to create a query that allows a user to select a specific date for which to show results. Following is sample SQL with a fixed criteria: SELECT qryShopJobsIO1.JOB_NO, qryShopJobsIO1.[TOTAL QUANTITY ORDERED], qryShopJobsIO1.[ENTRY DATE], qryShopJobsIO1.SumOfTotalHours FROM qryShopJobsIO1 WHERE (((qryShopJobsIO1.[ENTRY DATE])=#4/27/2010#)); This particular example returns no records. I know that I have records for which the ENTRY DATE field is 4/27/2010. I believe that the problem is that the default value of that field (in the table definition) is set to =Now() ...

Auto-Calculate
I have a spreadsheet that utilize the stock quote add-in from MSN. On a daily basis I refresh the add-in functions for the Highs, Lows, Last, Volume, etc. On occasion the spreadsheet reverts to manual caculation settings, and I have to press the F9 even after I updated the quotes. I've always preferred the any spreadsheets I open, blank or otherwise, the automatic setting selected for calculations. I consider this an annoyance. Has anyone experienced this glitch? Is there a fix for it? Ron_D Ron Excel takes the calculation mode from the first workbook that opens in a session. Sub...

auto copy self
How do I arrange for Outlook to automatically copy myself on every new, reply or forward email? If you mean keep a copy of all sent, see settings under Tools/Options/Email Options and Advanced Options David "rich" <steamuk@aol.com> wrote in message news:055c01c3664f$dadecd30$a001280a@phx.gbl... > How do I arrange for Outlook to automatically copy myself > on every new, reply or forward email? ...

eConnect -- where to find additional documentation and samples?
Hello, I'm working on my first eConnect implementation, and I'm finding the included documentation and samples a bit short of what I'd hope to see. My needs are fairly light (or at least I think so), but I've been having difficulty "digging deeper". Can anyone suggest a good resource (or groups of resources) that I can tap for support during this project? In other words, if this was your first eConnect project, where would you go for additional support outside of what was included in the eConnect SDK? The main goal of my implementation project is to post ...

When opening MS Outlook 2002 a window opens asking for network server?
Office XP Professional When I open MS Outlook a window opens up that is titled Microsoft LDAP Directory It asks for a server name, user name etc. This is a stand alone computer. Not on a network. Is there anyway of stopping this window from opening up each time I start Outlook? Thank You for your time Barry Barry, Your Outlook is configured to use an LDAP server for some reason. To remove the settings for an LDAP server, goto: 1) Tools 2) Email-Accounts Once in the Email-Accts window you will see four radio buttons(2 for E-mail and 2 for Directory) Click on the button next ...

Auto Scale Chart Macro -- Any improvements please?
This is the best way I've found to correctly scale a chart -- the only way I found to exclude a chart interpolating with #NA cells was to delete those cells containing #NA, and run the chart. This takes a long time on my computer. Wondering if there is a better way. This macro is directly taken from 2 excel mvps and modified; i believe a mehta and ron bovarty, but could be wrong. Thanks for taking a look. Sub AutoScaleYAxes() Dim ValuesArray(), SeriesValues As Variant Dim Ctr As Integer, TotCtr As Integer Application.Run "Extend_Stock_Data" Applic...

Auto correct or Auto complete
We are all familiar witht he auto correct or auto complete functions found in MS applications. Of course that means it is available in Access also. My question is this ... can this function be replicated within the DB, so that the set of auto correct items are part of the package rather than something that would have to be set up on each individual desktop system? It's use, for me, would primarily be within a memo field where medical abreviations, used as a shortcut, would convert to the true meaning as the user types them in. Ex: "prn" without quotes would change to. &qu...

display number as number name
I want to get the number name of the corresponding number i enter. Hi see: http://www.xldynamic.com/source/xld.xlFAQ0004.html "Kamala Kannan" wrote: > I want to get the number name of the corresponding number i enter. ...

Cannot open files.
I am having trouble opening files after saving them. I keep getting the message "cannot be opened because there are problems with the contents. Details says "Unspecified error" followed with the location in the "document.xml" file. ...

OWA auto login
I am trying to use the credentials from the forms authentication login to automaticaly log in to Outlook Web. I redirect to a URL with this format: http://UserName:Password@mailserver/exchange I have seen this example in other posts but this does not work for me. I still get the Outlook Windows Login prompt. Perry Perecli Manole wrote: > I am trying to use the credentials from the forms authentication > login to automaticaly log in to Outlook Web. I redirect to a URL with > this format: http://UserName:Password@mailserver/exchange > I have seen this example in other posts but t...

Test number of decimal places in Currency format
How can I interrogate the system (Windows, I guess) to find out how many decimal places are specified in its Currency format? Alternatively, how can I test a number that's been entered to ensure that the user did not enter more decimal places than the Windows currency format permits (Access will store what's entered, but I want to reject what's been entered if it's not according to the Regional settings). Bob Randy Birch has code to give you details about the defined Locale Currency information at http://vbnet.mvps.org/code/locale/localecurrency.htm Note, though, th...

Any way to get rid of an auto-suggestion in the login dialog box, for Exchange/OL using RPC over HTTP?
A client was using RPC over HTTP to two different Exchange servers (OL prompting for profile on startup). Both profiles were set up to prompt for credentials upon connection to Exchange. There's now only one Outlook profile needed; the other is gone and OL isn't prompting for the profile selection any longer, which is fine. However, Outlook is remembering domain1\user and domain2\user in the login dialog box, and I'd love to be able to get rid of the no-longer-valid credential dropdown suggestion. (The computer is not a member of a domain and hence always needs to be prom...

Count number of lines of text in a range/value.
To start, 1) Add a form w/ a textbox to your VBA project. 2) Set the textbox's AUTOSIZE property to False. 3) Set the textbox's MULTILINE property to False. In your code... 4) Call on the Form's SHOW method (modal or modeless is irrelevant). 5) Set the textbox's TEXT property to the (trimmed) value you are working with. 6) Set the textbox's AUTOSIZE property to True. 7) Set the textbox's MULTILINE property to True. 8) Save/get the textbox's LINECOUNT property. 9) Call on the form's HIDE method. btw, I assume no responsibility for the code. Use it at your own...

Auto look through subfolders
Please help. I can write a macro that will extract data from all excel files in a specific folder. What I need to be able to do is write a macro that will automatically extract data from excel files within folders and sub folders and sub sub folders etc For example the data is all held on the following directory: H:\development forms\2006 cost sheets\ And within that directory by customer - for example Tesco, Boots, Asda etc. These customers are then subdivided into product ranges - eg 1,2,3,4 etc and some futher subdivided by national or exclusive. All the excel files are in exactly th...

how to rotate excel table in word
I insert a excel worksheet in word and like to rotate it Select the area in the worksheet you want to move to Word. While hold down the shift key, pull-down Edit > Copy Picture. In Word, just paste. Because the item is now a picture, you can use the drawing toolbar to rotate it to any desired angle -- Gary''s Student "dro" wrote: > I insert a excel worksheet in word and like to rotate it Thanks, its working just fine for me. "Gary''s Student" wrote: > Select the area in the worksheet you want to move to Word. While hold down > the ...

document is reserved by
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel when I try to open a document is get a dialouge box that says 'is reserved by&quot;. <br><br>there are no other users with access to this document. <br><br>the dialouge box doesn't say who it's reserved by <br><br>the document has worked fine for months and suddenly I get this message Yeah, there's an issue that has recently occurred with Office 2008 that is causing this. When you open the document, Word locks the file you have opened, the backup file, an...

Formatting Problem
I've created a blank booklet of x no. of pages with page size of h7.25" x w4.75" with 0.5" margins all around. I've been provided with material on floppies to incorporate into the booklet. The material is in the wrong font type and size and needs considerable change in other formatting. This I've done by opening the document into a WORD document of the same dimensions as stated above and tailoring the content to this WORD document. There are some centering, indents, right or left alignment. When I then try to insert this into the booklet in Publisher, s...

Auto date
I am trying to create a field in a form that if anything is changed on it, it will automatically update the date to current date. Is this possible? Sojaminc wrote: >I am trying to create a field in a form that if anything is changed on it, it >will automatically update the date to current date. Is this possible? Make sure the last changed date/time field is in the form's record source table/query. Then use the form's BeforeUpdate event: Me.lastchanged = Now -- Marsh MVP [MS Access] Hi - You can do this in the On Dirty event of the form, which fires as soon as you m...

An auto reply to an auto reply!
Had the funniest situation yesterday. Somebody emailed a public folder we have set up. On there we have a rule to send a reply saying thanks for your email -someone will be with you shortly (we have to have this message on - it is for some website that recently went live). Now that auto reply went back to the guy who emailed - who must have sent it from a public folder himself (as he forwarded the original email from a public folder). The guy received our auto reply - and promptly his email system sent an auto reply to us. As is the way it is set up - our email system sent him an auto ...

Just in time debugging error
Hi, I installed CRM in a production Server where there is only CRM and SQL Server. I have this error every time i double click any button from the internet explorer window related to the CRM application: "An unhandled win32 exception occurred in iexplore.exe -9028-. Just-in-time debugging this exception failed with the following error: no installed debugger has just-in-time debugging enabled". This server only has the .net framework 2.0 but not visual studio installed. The error also happens in all the client machines. Thanks. Welcome to the world of CRM. Is this occuring ...