Macro to calculate an invoice number

M

Margaret Upton

In Word 2003 running Windows XP I used this macro to generate a number into
an invoice. It relied upon a file called Settings in C:\. It does not run
any more and when I press debug it highlights the part below. Have pasted
in the whole macro. Again, please can anyone help.

Margaret

System.PrivateProfileString("c:\Settings.txt, "MacroSettings",_
"Order") =+1 section


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#")
 
D

Doug Robbins - Word MVP

From where did this line of code come?

System.PrivateProfileString("c:\Settings.txt, "MacroSettings",_
"Order") =+1 section

It is not in the macro in the article "Creating sequentially numbered
documents (such as invoices)" at:

http://www.word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm


--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.
 
M

Margaret Upton

Thank you Doug. The full macro is beneath that line, this was the line that
was highlighted as being wrong.

Margaret
 
M

Margaret Upton

Have looked at your page and I think that one looks a bit complicated for
me, the one I was given years ago worked very well, it just will not work
with this new version of Word for some reason. I am so grateful for all
your help always, thank you.

Margaret
 
G

Graham Mayor

It won't work because the error line is superfluous and the syntax is wrong.
You can get the macro to work again by deleting that line. However, the
macro adds the number next to the bookmark. It would be better to add the
number to the bookmark.

Dim Order As String
Dim oRng As Range
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
With ActiveDocument
Set oRng = .Bookmarks("Order").Range
oRng.Text = Format(Order, "00#")
.Bookmarks.Add "Order", oRng
End With

The code on my web site is essentially similar except it uses a docvariable
field rather than the bookmark. It also includes code to reset the start
number, some formatting and a lot of error trapping. The code is annotated
to demonstrate how it works.

If you are interested, I have been developing an automated invoice template
for Word 2007 with Greg Maxey. It would be interesting to see how it stands
up from a user perspective. Contact me via my web site if you would like to
try it.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

Margaret Upton

Graham, thank you again. If I explain, I am a secretary who is very
interested in computers and setting the office to work as efficiently as
possible. Over the years I have set up all kinds of templates and macros to
work for them. Some by recording macros and putting in odd bits of code to
tweak them. Someone like yourself would have a fit at my macros, but they
work for me. I get templates to put in the vat, add up, etc. Put up menus
so we can choose standard documents with fields in them etc. The automated
invoice was actually a thing I did years ago for another secretary I know
who works for a different company, but now she has Word 2007 it does not
work. I copied very successfully (I am good at creating forms !!) their
invoice template and then got it to generate numbers for her. I will not be
able to try your code for a couple of days because I am working for the next
2 days in the office. I would like to try your template, so will contact
you via your website. Thank you again so much. Will let you know at the
weekend about the code you have given me.

Margaret
 

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