Resetting a macro

K

Kerri

I am creating a template for a purchase order that
includes a macro that automatically gives each new
purchase order the next sequential number. I finally have
the macro working just fine, but I need to reset it to
start counting from 1. I had to test it to make sure it
worked, but now I need to start it at the beginning.
Thanks for your help.
Kerri
 
J

Jay Freedman

Hi, Kerri,

Without knowing where the macro stores the value of the current number, it's
impossible to say how to reset it. I can think of these possibilities
offhand: In a separate file (usually *.ini or *.txt), in the registry, in a
document variable or document property of the template, or by looking at the
names of the files in a directory where all the documents are stored.

If you can't figure it out, post the code of the macro in a followup (please
just paste the code into the body of the post, not as an attachment).
 
G

Guest

Jay,
Thanks for your response. Here is the code.
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, "000#")
ActiveDocument.SaveAs FileName:="purchase order" & Format
(Order, "000#")

End Sub

Does this help?
Kerri
 
J

Jay Freedman

Hi, Kerri,

The answer is in the two statements that use the PrivateProfileString
function: The last-used number is stored in the file C:\Settings.Txt. If you
open that file, you'll see something like this:

[MacroSettings]
Order=12

which means that the last time you ran the macro it printed purchase order
number 12, and the next one will be 13 (because of the line Order = Order +
1).

To start over at 1, you can just change the number after the equal sign to
0. Then save C:\Settings.Txt, and you're good to go.
 
K

Kerri

Thank you, Thank you, Thank you!
It worked perfectly!!

-----Original Message-----
Hi, Kerri,

The answer is in the two statements that use the PrivateProfileString
function: The last-used number is stored in the file C:\Settings.Txt. If you
open that file, you'll see something like this:

[MacroSettings]
Order=12

which means that the last time you ran the macro it printed purchase order
number 12, and the next one will be 13 (because of the line Order = Order +
1).

To start over at 1, you can just change the number after the equal sign to
0. Then save C:\Settings.Txt, and you're good to go.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://www.mvps.org/word

Jay,
Thanks for your response. Here is the code.
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, "000#")
ActiveDocument.SaveAs FileName:="purchase order" & Format
(Order, "000#")

End Sub

Does this help?
Kerri


.
 

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