Hi
I didn't know anything about macros and VBA for nowadays but I want to make
my documents numbered sequentially and I looked at some related sites ( such
as http://word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm ). Also I read 70 pages
about my subject at this site :) I changed the code as the following for me:
Sub AutoNew()
Order = System.PrivateProfileString("\\server\Counter.Txt", _
"MacroSettings", "Order")
If Order = "" Then
Order = 1
Else
Order = Order + 1
End If
System.PrivateProfileString("\\server\Counter.txt", "MacroSettings", _
"Order") = Order
ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order, "00#")
ActiveDocument.SaveAs FileName:="\\server\DocumentName Ref-06-" &
Format(Order, "00#")
End Sub
As you can see In my document I have a Ref-06-XXX part and everytime I
opened the template document it adds one to Ref like “Ref-06-001”,
“Ref-06-002”, “Ref-06-003”... and also it creates the document at “\\server\”
like “DocumentName Ref-06-001”, “DocumentName Ref-06-002”, “DocumentName
Ref-06-003”...
But the problem is it saves the document after it opens the new numbered
document so if i made a mistake to open a new document i should delete the
last document that was created and also change the order number in the
“Counter.txt” to -1. I hope I had explained my problem well :) So I think
about the problem and have some answers like;
* Macro shouldn't save the document at the beginning (after the creation of
the new document). It would save the document after I made changes on the
document and I think that the document have that Ref number on it. So it
should save the document after I made my changes on document (before closing
the document).
As I said at the beginning I don’t know VBA codes so I need help from you. I
know that this is too easy for experts. Thanks for your help this very moment
:)
Doug Robbins - Word MVP - 09 Feb 2006 12:37 GMT
Change the AutoNew macro to
Sub AutoNew()
Order = System.PrivateProfileString("\\server\Counter.Txt", _
"MacroSettings", "Order")
If Order = "" Then
Order = 1
Else
Order = Order + 1
End If
ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order, "00#")
End Sub
and create another macro in the template with the name FileSaveAs() that
contains the following code:
Sub FileSaveAs()
Order = System.PrivateProfileString("\\server\Counter.Txt", _
"MacroSettings", "Order")
If Order = "" Then
Order = 1
Else
Order = Order + 1
End If
System.PrivateProfileString("\\server\Counter.txt", "MacroSettings", _
"Order") = Order
ActiveDocument.SaveAs FileName:="\\server\DocumentName Ref-06-" &
Format(Order, "00#")
End Sub

Signature
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
> Hi
>
[quoted text clipped - 53 lines]
> moment
> :)
^DiGNiTy^ - 09 Feb 2006 14:23 GMT
Thank you very much Mr. Robbins for helping but I forgot to tell my real
problem. The critical point is if I didn't use File Save As macro (if I
didn't save the document) the order number in the "Counter.txt" wouldn't
increase +1 in the next opened document. So if I opened a new document and
wanted to cancel it (close it without saving) the autonew macro wouldn't give
the newer document to a new +1 increased number. It should give the canceled
document's number to the new document ;) I hope that I explained my problem
and my problem's gonna be solved. Thanks again for your help this very moment
Very truly yours...
^DiGNiTy^
"Doug Robbins - Word MVP":
> Change the AutoNew macro to
>
[quoted text clipped - 34 lines]
>
> End Sub
Jean-Guy Marcil - 09 Feb 2006 14:58 GMT
^DiGNiTy^ was telling us:
^DiGNiTy^ nous racontait que :
> Thank you very much Mr. Robbins for helping but I forgot to tell my
> real problem. The critical point is if I didn't use File Save As
[quoted text clipped - 6 lines]
> problem's gonna be solved. Thanks again for your help this very
> moment
Since you wrote:
"I didn't know anything about macros and VBA "
I do not think this is something you can do, and unless someone has the time
to write the code, I am afraid the easiest for you right now is to manually
modify the "Counter.txt" file if you need to adjust the sequence number.
When you need to change the document sequence number, open "Counter.txt"
with Notepad, change the number under the [Order] setting and save the file.

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org