numbering documents

B

Barb

I am trying to set up a purchase order template. I need
to include a macro that will cause it to come up with the
next consecutive P.O. number each time the template is
opened. A friend found me some instructions on the
internet but I get an error message when I try to create
the macro and when I try to run it, obviously. Here's
what I have:
Sub autonumber()
Dim MyString, autoNumb
FileToOpen = "c:\windows\autonumberfile.txt"
Open FileToOpen for Input As #1
Input #1, autoNumb
Close #1
ActiveDocument.Bookmarks("autonumb").Select
Selection.InsertAfterText:=autoNumb
autoNumb = autoNumb + 1
Open FileToOpen For Output As #1
Write #1, autoNumb
Close #1
End Sub

I rarely use macros so I have no idea what is wrong with
this one. Maybe it was written for a different Word
version and doesn't work in 2002. I would appreciate any
guidance anyone can give me. I posted this in the
numbering newsgroup but thought VBA might be a better
place.

Thanks!
Barb
 
J

Jay Freedman

Hi Barb,

There doesn't appear to be anything wrong with the macro itself, but it
makes a couple of assumptions that may not be true.

- It assumes that a file named c:\windows\autonumberfile.txt already exists,
and that it contains a number in its first line. If you haven't already
created such a file, do it now.

- It assumes that the template contains a bookmark named autonumb, which has
been propagated to the current document.

It would be possible to add programming to the macro to deal with the
situation when either or both assumptions are wrong. Unfortunately, a bit
more than I have time for just now.

Here's another web page with a similar macro:
http://word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top