Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Numbering / April 2005

Tip: Looking for answers? Try searching our database.

Auto sequential number to a document - For Invoice

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Irshad Alam - 06 Apr 2005 05:39 GMT
This is in reference to the earlier posted Question and Answer related to
same topic, based on that I tried to do and failed.
I visited the below site, copied the codes, Open a new document create a
form type document and inserted Bookmark and a Macro named "AutoNew" and
pasted the code. Save the document as a Template.
http://word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm

When I open the template file, first time it works fine, It puts the first
number as 001 and save the file as Path001.
But when I open the document second time onwards, it produces the same
number (001) instead of 002 onwards.

I dont know where is the mistake I am doing. The code I have pasted is as
follows :

Sub AutoNew()

Order = System.PrivateProfileString("C:\Settings.Txt", _
       "MacroSettings", "Order")

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

System.PrivateProfileString("C:\Settings.txt", "MacroSettings", _
       "Order") = Order

ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order, "00#")
ActiveDocument.SaveAs FileName:="path" & Format(Order, "00#")

End Sub

I am using this on Windows XP operating system and MS office 2000.

Please advise me.

Regards.

Irshad Alam
Abu Dhabi -UAE
Kathy - 06 Apr 2005 13:26 GMT
Hi

I pasted the code into Word 2000 on Windows 2000, added Dim Order As Variant
under Sub AutoNew() and it works fine (it starts as a string and becomes an
integer).

To make it work as intended, you have to save it as a template (*.dot), then
create a NEW document from it each time (it uses AutoNew) by going File,
New, and double-clicking the template you saved. Then it will create and
save path001.doc in My Documents. The you would finish this document and
re-save it. To make path002.doc, you must do File, New again (or run the
macro manually).

Does the user have write access to C:\ (to edit settings.txt)? Most don't-
I'd try a different path. Why don't you open the template and step through
the code with F8.  Then you can see where it goes wrong. If you stop
pressing F8 AFTER it has written the new value for Order (when THIS line is
highlighted: ActiveDocument.Bookmarks("Order").Range.InsertBefore
Format(Order, "00#") ),  you can see whether it has updated settings.txt or
not (open it in notepad).

HTH

Kathy

> This is in reference to the earlier posted Question and Answer related to
> same topic, based on that I tried to do and failed.
[quoted text clipped - 38 lines]
> Irshad Alam
> Abu Dhabi -UAE
Irshad Alam - 09 Apr 2005 12:41 GMT
First of all thank you very much for your tips. I tried you said method and
it worked.

Additional Question related to it, I want to bring auto increment number at
the place the cursor is. Not only at the bookmark place and all documents,
whether its template or normal. While typing I may need this increment number
and I want to place the value exactly at the place of my curso.

What changes I should do on the code to do this.

Please advise.

> Hi
>
[quoted text clipped - 63 lines]
> > Irshad Alam
> > Abu Dhabi -UAE
Doug Robbins - 25 Apr 2005 19:24 GMT
Use Selection.InsertBefore instead of
ActiveDocument.Bookmarks("bookmark").Range.InsertBefore

(Don't have access to the internet while writing this so can't check on
exactly what the original code is.)

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

> First of all thank you very much for your tips. I tried you said method
> and
[quoted text clipped - 91 lines]
>> > Irshad Alam
>> > Abu Dhabi -UAE

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.