View Single Post
  #8   Report Post  
Posted to microsoft.public.word.docmanagement
snulton snulton is offline
external usenet poster
 
Posts: 25
Default How do I set up automatically suceeding numbers in Word?

Sorry that it has taken so long to get back to you with the on going
challenge, I was out of town last week and finally got caught up.

After setting up the Macro, upon opening a document I get a variety of error
messeges one of which says "Compile error: Expected End Sub"

This is what I have set up:


Sub MAIN()
'
' AutoExec.MAIN Macro
' Macro created 10/5/2007 by Scott Nulton
'
Sub AutoNew()

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

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

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

ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order,
"0000#")
ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#")



End Sub



"Jay Freedman" wrote:

I think you're misunderstanding the "00#" expression. That is just
supposed to represent the form of the number -- how many digits to
display -- and not the number itself. You don't change that expression
to the start number.

From the example you gave, I suspect what you're trying to do is
create a number where the first four digits are the year, the next two
are the month, and the last two are a sequence number that starts over
at 1 for each month. If that's true, you're going about it wrong -- if
you put the fixed string "200710" at the beginning, that's fine for
October 2007 but it will be wrong for November, and even more wrong
next year. The macro can take care of the year and month for you with
just a little extra programming. Replace the lines

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

with these lines (to avoid mistakes, use copy/paste instead of trying
to retype):

ActiveDocument.Bookmarks("Order").Range.InsertBefo re _
Format(Now, "yyyyMM") & Format(Order, "0#")
ActiveDocument.SaveAs FileName:="path" & _
Format(Now, "yyyyMM") & Format(Order, "0#")

Note that you have to replace "path" in the third line with the actual
path to the folder where you want the document to be saved.

The other thing is that, on the first day of each month, you have to
delete the Settings.txt file and let the macro create a new one that
contains the number 1, so the number in the first document will be
like 20071101.

On Fri, 5 Oct 2007 16:46:02 -0700, snulton
wrote:

It was'nt in my Templates folder because I was testing it out before I put it
on my Server which is where I store all my templates related to my business.
I tried to preset the start number to the next one that we need
(i.e."2007100#") but it did not open a successive number it opened a document
with a number 2007100120071001. The same thing happened when I had only the
three digit number 001 turned into 001001 and it was that way on each one I
opened.

"Jay Freedman" wrote:

Did you set up the macro in a template stored in your Templates
folder? Word really doesn't like macros in documents, or in templates
that aren't in the Templates folder, because that's a favorite way to
spread macro viruses.

Assuming it is in a template, go to Tools Macro Security and set
the security level to Medium. On the second tab of the dialog, check
the box for "Trust all installed templates and add-ins". That should
make sure the macros are enabled.

The number-format pattern will work with eight digits; just change it
to "0000000#".

On Fri, 5 Oct 2007 16:08:01 -0700, snulton
wrote:

I have set up the Macro as on the page however when I attempt to open the
template Microsoft Basic pops up with the messege "The macros in this project
are disabled. Please refer to the online help or documentation of the host
application to determine how to enable macros." then I got a popup trying to
debug the first of the last two commands.

Also is the value "00#" a locked in numeric value or will it work with eight
digits?

"Jay Freedman" wrote:

snulton wrote:
I have a template that has a space for a number. I want each
successive document opened using that template to have a new number
that is the next number in sucession, i.e. - after opening 20071001,
the next time that I access that template should open 2001002.

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


--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.