Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
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. |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
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. |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
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. |
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
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. |
#5
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
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. |
#6
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
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. |
#7
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
I understood that, but what was happening when the macro was set to 00#, the
first number came out 001. The second time I opened the template the number read 001001. As far as the date was concerned, I was only trying to establish a starting point like not starting a checking account with the first check number 001. Thanks for your helping a "dumb" contractor. : - } "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. |
#8
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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. |
#9
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
Hi Scott,
In VBA, every "Sub" statement must have a matching "End Sub" statement, with all the commands of the macro in between. You have a "Sub MAIN()" statement without any matching "End Sub". Delete the "Sub Main()" line (and optionally also delete the four lines of comments that follow it). Then the "Sub AutoNew()" will match the "End Sub" at the bottom of the code, and that should stop the error message. snulton wrote: 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. |
#10
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
I have almost completely started over due to receiving a Microsoft Visual Basic
Run-time error `5941' The requested memer of the collection does not exist. When I click on the Debug button the line reading ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "00#") is hi-lited. "Jay Freedman" wrote: Hi Scott, In VBA, every "Sub" statement must have a matching "End Sub" statement, with all the commands of the macro in between. You have a "Sub MAIN()" statement without any matching "End Sub". Delete the "Sub Main()" line (and optionally also delete the four lines of comments that follow it). Then the "Sub AutoNew()" will match the "End Sub" at the bottom of the code, and that should stop the error message. snulton wrote: 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. |
#11
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
That error is telling you that VBA couldn't find any bookmark named "Order"
in your document. Look again at the article -- the second paragraph begins "In the template from which you create the document, insert a bookmark named Order in the location where you want the sequential number to appear." snulton wrote: I have almost completely started over due to receiving a Microsoft Visual Basic Run-time error `5941' The requested memer of the collection does not exist. When I click on the Debug button the line reading ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "00#") is hi-lited. "Jay Freedman" wrote: Hi Scott, In VBA, every "Sub" statement must have a matching "End Sub" statement, with all the commands of the macro in between. You have a "Sub MAIN()" statement without any matching "End Sub". Delete the "Sub Main()" line (and optionally also delete the four lines of comments that follow it). Then the "Sub AutoNew()" will match the "End Sub" at the bottom of the code, and that should stop the error message. snulton wrote: 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. |
#12
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
Yes! I forgot the bookmark. Will the sequencial numbering work if I lock the form when savesd as template? "Jay Freedman" wrote: That error is telling you that VBA couldn't find any bookmark named "Order" in your document. Look again at the article -- the second paragraph begins "In the template from which you create the document, insert a bookmark named Order in the location where you want the sequential number to appear." snulton wrote: I have almost completely started over due to receiving a Microsoft Visual Basic Run-time error `5941' The requested memer of the collection does not exist. When I click on the Debug button the line reading ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "00#") is hi-lited. "Jay Freedman" wrote: Hi Scott, In VBA, every "Sub" statement must have a matching "End Sub" statement, with all the commands of the macro in between. You have a "Sub MAIN()" statement without any matching "End Sub". Delete the "Sub Main()" line (and optionally also delete the four lines of comments that follow it). Then the "Sub AutoNew()" will match the "End Sub" at the bottom of the code, and that should stop the error message. snulton wrote: 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. |
#13
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
I now recieve a Run-time error `4605`
This method or property is not available because the object refers to a protected area of the document. "Jay Freedman" wrote: That error is telling you that VBA couldn't find any bookmark named "Order" in your document. Look again at the article -- the second paragraph begins "In the template from which you create the document, insert a bookmark named Order in the location where you want the sequential number to appear." snulton wrote: I have almost completely started over due to receiving a Microsoft Visual Basic Run-time error `5941' The requested memer of the collection does not exist. When I click on the Debug button the line reading ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "00#") is hi-lited. "Jay Freedman" wrote: Hi Scott, In VBA, every "Sub" statement must have a matching "End Sub" statement, with all the commands of the macro in between. You have a "Sub MAIN()" statement without any matching "End Sub". Delete the "Sub Main()" line (and optionally also delete the four lines of comments that follow it). Then the "Sub AutoNew()" will match the "End Sub" at the bottom of the code, and that should stop the error message. snulton wrote: 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. |
#14
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
You can do either of two things:
- In the template, insert continuous-type section breaks before and after the paragraph containing the bookmark. When you protect the document (using the Tools Protect Document menu item, not the lock icon on the Forms toolbar), click the "Select sections" link and uncheck the section that contains the bookmark. - Or, in the macro, insert new code before and after the InsertBefore line like this: If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "0000#") ActiveDocument.Protect ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") That will turn off the protection just long enough to insert the sequence number, and then turn the protection on again. -- 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. snulton wrote: I now recieve a Run-time error `4605` This method or property is not available because the object refers to a protected area of the document. "Jay Freedman" wrote: That error is telling you that VBA couldn't find any bookmark named "Order" in your document. Look again at the article -- the second paragraph begins "In the template from which you create the document, insert a bookmark named Order in the location where you want the sequential number to appear." snulton wrote: I have almost completely started over due to receiving a Microsoft Visual Basic Run-time error `5941' The requested memer of the collection does not exist. When I click on the Debug button the line reading ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "00#") is hi-lited. "Jay Freedman" wrote: Hi Scott, In VBA, every "Sub" statement must have a matching "End Sub" statement, with all the commands of the macro in between. You have a "Sub MAIN()" statement without any matching "End Sub". Delete the "Sub Main()" line (and optionally also delete the four lines of comments that follow it). Then the "Sub AutoNew()" will match the "End Sub" at the bottom of the code, and that should stop the error message. snulton wrote: 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. |
#15
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
Thank you! One more thing, how do I have different documents have their own
sets of sequencial numbers? Right now the sequence is working but I am using the same "Order" in four different documents, two different contracts, one bid proposal and one invoice. "Jay Freedman" wrote: You can do either of two things: - In the template, insert continuous-type section breaks before and after the paragraph containing the bookmark. When you protect the document (using the Tools Protect Document menu item, not the lock icon on the Forms toolbar), click the "Select sections" link and uncheck the section that contains the bookmark. - Or, in the macro, insert new code before and after the InsertBefore line like this: If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "0000#") ActiveDocument.Protect ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") That will turn off the protection just long enough to insert the sequence number, and then turn the protection on again. -- 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. snulton wrote: I now recieve a Run-time error `4605` This method or property is not available because the object refers to a protected area of the document. "Jay Freedman" wrote: That error is telling you that VBA couldn't find any bookmark named "Order" in your document. Look again at the article -- the second paragraph begins "In the template from which you create the document, insert a bookmark named Order in the location where you want the sequential number to appear." snulton wrote: I have almost completely started over due to receiving a Microsoft Visual Basic Run-time error `5941' The requested memer of the collection does not exist. When I click on the Debug button the line reading ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "00#") is hi-lited. "Jay Freedman" wrote: Hi Scott, In VBA, every "Sub" statement must have a matching "End Sub" statement, with all the commands of the macro in between. You have a "Sub MAIN()" statement without any matching "End Sub". Delete the "Sub Main()" line (and optionally also delete the four lines of comments that follow it). Then the "Sub AutoNew()" will match the "End Sub" at the bottom of the code, and that should stop the error message. snulton wrote: 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. |
#16
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
First, you have to use a different template for each sequence. Since
you're doing forms of different kinds, I assume that's already true. Then the other part is to visit the macro code in each template and put in a different name for the file that stores the current number. Now they all say "C:\Settings.Txt" in two place (at least I hope they do -- the code you posted before has "C:\.txt" in the second place, which is wrong). On Thu, 18 Oct 2007 14:34:00 -0700, snulton wrote: Thank you! One more thing, how do I have different documents have their own sets of sequencial numbers? Right now the sequence is working but I am using the same "Order" in four different documents, two different contracts, one bid proposal and one invoice. "Jay Freedman" wrote: You can do either of two things: - In the template, insert continuous-type section breaks before and after the paragraph containing the bookmark. When you protect the document (using the Tools Protect Document menu item, not the lock icon on the Forms toolbar), click the "Select sections" link and uncheck the section that contains the bookmark. - Or, in the macro, insert new code before and after the InsertBefore line like this: If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "0000#") ActiveDocument.Protect ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") That will turn off the protection just long enough to insert the sequence number, and then turn the protection on again. -- 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. snulton wrote: I now recieve a Run-time error `4605` This method or property is not available because the object refers to a protected area of the document. "Jay Freedman" wrote: That error is telling you that VBA couldn't find any bookmark named "Order" in your document. Look again at the article -- the second paragraph begins "In the template from which you create the document, insert a bookmark named Order in the location where you want the sequential number to appear." snulton wrote: I have almost completely started over due to receiving a Microsoft Visual Basic Run-time error `5941' The requested memer of the collection does not exist. When I click on the Debug button the line reading ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "00#") is hi-lited. "Jay Freedman" wrote: Hi Scott, In VBA, every "Sub" statement must have a matching "End Sub" statement, with all the commands of the macro in between. You have a "Sub MAIN()" statement without any matching "End Sub". Delete the "Sub Main()" line (and optionally also delete the four lines of comments that follow it). Then the "Sub AutoNew()" will match the "End Sub" at the bottom of the code, and that should stop the error message. snulton wrote: 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. |
#17
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
Yes, each is a different template for a different kind of Word document.
Sorry to be so dense, but could you give me an example of the different names? I am not sure that I understand. Is there something that I could download that explains it so I don't bother you further? "Jay Freedman" wrote: First, you have to use a different template for each sequence. Since you're doing forms of different kinds, I assume that's already true. Then the other part is to visit the macro code in each template and put in a different name for the file that stores the current number. Now they all say "C:\Settings.Txt" in two place (at least I hope they do -- the code you posted before has "C:\.txt" in the second place, which is wrong). On Thu, 18 Oct 2007 14:34:00 -0700, snulton wrote: Thank you! One more thing, how do I have different documents have their own sets of sequencial numbers? Right now the sequence is working but I am using the same "Order" in four different documents, two different contracts, one bid proposal and one invoice. "Jay Freedman" wrote: You can do either of two things: - In the template, insert continuous-type section breaks before and after the paragraph containing the bookmark. When you protect the document (using the Tools Protect Document menu item, not the lock icon on the Forms toolbar), click the "Select sections" link and uncheck the section that contains the bookmark. - Or, in the macro, insert new code before and after the InsertBefore line like this: If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "0000#") ActiveDocument.Protect ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") That will turn off the protection just long enough to insert the sequence number, and then turn the protection on again. -- 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. snulton wrote: I now recieve a Run-time error `4605` This method or property is not available because the object refers to a protected area of the document. "Jay Freedman" wrote: That error is telling you that VBA couldn't find any bookmark named "Order" in your document. Look again at the article -- the second paragraph begins "In the template from which you create the document, insert a bookmark named Order in the location where you want the sequential number to appear." snulton wrote: I have almost completely started over due to receiving a Microsoft Visual Basic Run-time error `5941' The requested memer of the collection does not exist. When I click on the Debug button the line reading ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "00#") is hi-lited. "Jay Freedman" wrote: Hi Scott, In VBA, every "Sub" statement must have a matching "End Sub" statement, with all the commands of the macro in between. You have a "Sub MAIN()" statement without any matching "End Sub". Delete the "Sub Main()" line (and optionally also delete the four lines of comments that follow it). Then the "Sub AutoNew()" will match the "End Sub" at the bottom of the code, and that should stop the error message. snulton wrote: 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. |
#18
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
No download, you're off in an area that's sort of "you just need to
understand what you're doing". :-) Exactly what you use for the names isn't terribly important as long as (a) they're valid file names, (b) there's a different one for each template, and (c) you can recognize them when you see them. So I'll suggest that for each one you take the name of the template (assuming that's something you recognize as being associated with that type of form), add the word "sequence" and the extension ".txt". For example, if you have a template named "Contract A.dot" and one named "Contract B.dot", then the corresponding names inside the macro could be "Contract A sequence.txt" and "Contract B sequence.txt". Put a valid path in front of each name, for example "C:\Contract A sequence.txt", and put that into the macro in the template for Contract A. Put "C:\Contract B sequence.txt" into the macro in the template for Contract B. Do similarly for the other templates -- each one gets a filename in its macro that corresponds to that template only. Am I making sense yet? snulton wrote: Yes, each is a different template for a different kind of Word document. Sorry to be so dense, but could you give me an example of the different names? I am not sure that I understand. Is there something that I could download that explains it so I don't bother you further? "Jay Freedman" wrote: First, you have to use a different template for each sequence. Since you're doing forms of different kinds, I assume that's already true. Then the other part is to visit the macro code in each template and put in a different name for the file that stores the current number. Now they all say "C:\Settings.Txt" in two place (at least I hope they do -- the code you posted before has "C:\.txt" in the second place, which is wrong). On Thu, 18 Oct 2007 14:34:00 -0700, snulton wrote: Thank you! One more thing, how do I have different documents have their own sets of sequencial numbers? Right now the sequence is working but I am using the same "Order" in four different documents, two different contracts, one bid proposal and one invoice. "Jay Freedman" wrote: You can do either of two things: - In the template, insert continuous-type section breaks before and after the paragraph containing the bookmark. When you protect the document (using the Tools Protect Document menu item, not the lock icon on the Forms toolbar), click the "Select sections" link and uncheck the section that contains the bookmark. - Or, in the macro, insert new code before and after the InsertBefore line like this: If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "0000#") ActiveDocument.Protect ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") That will turn off the protection just long enough to insert the sequence number, and then turn the protection on again. -- 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. snulton wrote: I now recieve a Run-time error `4605` This method or property is not available because the object refers to a protected area of the document. "Jay Freedman" wrote: That error is telling you that VBA couldn't find any bookmark named "Order" in your document. Look again at the article -- the second paragraph begins "In the template from which you create the document, insert a bookmark named Order in the location where you want the sequential number to appear." snulton wrote: I have almost completely started over due to receiving a Microsoft Visual Basic Run-time error `5941' The requested memer of the collection does not exist. When I click on the Debug button the line reading ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "00#") is hi-lited. "Jay Freedman" wrote: Hi Scott, In VBA, every "Sub" statement must have a matching "End Sub" statement, with all the commands of the macro in between. You have a "Sub MAIN()" statement without any matching "End Sub". Delete the "Sub Main()" line (and optionally also delete the four lines of comments that follow it). Then the "Sub AutoNew()" will match the "End Sub" at the bottom of the code, and that should stop the error message. snulton wrote: 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. |
#19
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
If I have it correctly, then:
If the original Macro that you showed me: 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.Insert Before Format(Order. €0000#€¯) ActiveDocument.SaveAs FileName:=€¯path€¯ & Format(Order, €0000#€¯) End Sub Then the modification would be: Sub AutoNew() Order = System.PrivateProfileString(€C:\RemContract Sequence.Txt€¯,€¯MacroSettings€¯,€¯Order) If Order = €€¯ Then Order = 1 Else Order = Order + 1 End If System.PrivateProfileString(€C:\RemContract Sequence.Txt€¯,€¯MacroSettings€¯,€¯Order) = Order ActiveDocument.Bookmarks(€Order€¯).Range.Insert Before Format(Order. €0000#€¯) ActiveDocument.SaveAs FileName:=€¯path€¯ & Format(Order, €0000#€¯) End Sub Is this correct? "Jay Freedman" wrote: No download, you're off in an area that's sort of "you just need to understand what you're doing". :-) Exactly what you use for the names isn't terribly important as long as (a) they're valid file names, (b) there's a different one for each template, and (c) you can recognize them when you see them. So I'll suggest that for each one you take the name of the template (assuming that's something you recognize as being associated with that type of form), add the word "sequence" and the extension ".txt". For example, if you have a template named "Contract A.dot" and one named "Contract B.dot", then the corresponding names inside the macro could be "Contract A sequence.txt" and "Contract B sequence.txt". Put a valid path in front of each name, for example "C:\Contract A sequence.txt", and put that into the macro in the template for Contract A. Put "C:\Contract B sequence.txt" into the macro in the template for Contract B. Do similarly for the other templates -- each one gets a filename in its macro that corresponds to that template only. Am I making sense yet? snulton wrote: Yes, each is a different template for a different kind of Word document. Sorry to be so dense, but could you give me an example of the different names? I am not sure that I understand. Is there something that I could download that explains it so I don't bother you further? "Jay Freedman" wrote: First, you have to use a different template for each sequence. Since you're doing forms of different kinds, I assume that's already true. Then the other part is to visit the macro code in each template and put in a different name for the file that stores the current number. Now they all say "C:\Settings.Txt" in two place (at least I hope they do -- the code you posted before has "C:\.txt" in the second place, which is wrong). On Thu, 18 Oct 2007 14:34:00 -0700, snulton wrote: Thank you! One more thing, how do I have different documents have their own sets of sequencial numbers? Right now the sequence is working but I am using the same "Order" in four different documents, two different contracts, one bid proposal and one invoice. "Jay Freedman" wrote: You can do either of two things: - In the template, insert continuous-type section breaks before and after the paragraph containing the bookmark. When you protect the document (using the Tools Protect Document menu item, not the lock icon on the Forms toolbar), click the "Select sections" link and uncheck the section that contains the bookmark. - Or, in the macro, insert new code before and after the InsertBefore line like this: If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "0000#") ActiveDocument.Protect ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") That will turn off the protection just long enough to insert the sequence number, and then turn the protection on again. -- 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. snulton wrote: I now recieve a Run-time error `4605` This method or property is not available because the object refers to a protected area of the document. "Jay Freedman" wrote: That error is telling you that VBA couldn't find any bookmark named "Order" in your document. Look again at the article -- the second paragraph begins "In the template from which you create the document, insert a bookmark named Order in the location where you want the sequential number to appear." snulton wrote: I have almost completely started over due to receiving a Microsoft Visual Basic Run-time error `5941' The requested memer of the collection does not exist. When I click on the Debug button the line reading ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "00#") is hi-lited. "Jay Freedman" wrote: Hi Scott, In VBA, every "Sub" statement must have a matching "End Sub" statement, with all the commands of the macro in between. You have a "Sub MAIN()" statement without any matching "End Sub". Delete the "Sub Main()" line (and optionally also delete the four lines of comments that follow it). Then the "Sub AutoNew()" will match the "End Sub" at the bottom of the code, and that should stop the error message. snulton wrote: 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. |
#20
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
Yes, that's correct. :-)
snulton wrote: If I have it correctly, then: If the original Macro that you showed me: Sub AutoNew() Order = System.PrivateProfileString("C:\Settings.Txt","Mac roSettings","Order) If Order = "" Then Order = 1 Else Order = Order + 1 End If System.PrivateProfileString("C:\Settings.txt", "MacroSettings,"Order") = Order ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order. "0000#") ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") End Sub Then the modification would be: Sub AutoNew() Order = System.PrivateProfileString("C:\RemContract Sequence.Txt","MacroSettings","Order) If Order = "" Then Order = 1 Else Order = Order + 1 End If System.PrivateProfileString("C:\RemContract Sequence.Txt","MacroSettings","Order) = Order ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order. "0000#") ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") End Sub Is this correct? "Jay Freedman" wrote: No download, you're off in an area that's sort of "you just need to understand what you're doing". :-) Exactly what you use for the names isn't terribly important as long as (a) they're valid file names, (b) there's a different one for each template, and (c) you can recognize them when you see them. So I'll suggest that for each one you take the name of the template (assuming that's something you recognize as being associated with that type of form), add the word "sequence" and the extension ".txt". For example, if you have a template named "Contract A.dot" and one named "Contract B.dot", then the corresponding names inside the macro could be "Contract A sequence.txt" and "Contract B sequence.txt". Put a valid path in front of each name, for example "C:\Contract A sequence.txt", and put that into the macro in the template for Contract A. Put "C:\Contract B sequence.txt" into the macro in the template for Contract B. Do similarly for the other templates -- each one gets a filename in its macro that corresponds to that template only. Am I making sense yet? snulton wrote: Yes, each is a different template for a different kind of Word document. Sorry to be so dense, but could you give me an example of the different names? I am not sure that I understand. Is there something that I could download that explains it so I don't bother you further? "Jay Freedman" wrote: First, you have to use a different template for each sequence. Since you're doing forms of different kinds, I assume that's already true. Then the other part is to visit the macro code in each template and put in a different name for the file that stores the current number. Now they all say "C:\Settings.Txt" in two place (at least I hope they do -- the code you posted before has "C:\.txt" in the second place, which is wrong). On Thu, 18 Oct 2007 14:34:00 -0700, snulton wrote: Thank you! One more thing, how do I have different documents have their own sets of sequencial numbers? Right now the sequence is working but I am using the same "Order" in four different documents, two different contracts, one bid proposal and one invoice. "Jay Freedman" wrote: You can do either of two things: - In the template, insert continuous-type section breaks before and after the paragraph containing the bookmark. When you protect the document (using the Tools Protect Document menu item, not the lock icon on the Forms toolbar), click the "Select sections" link and uncheck the section that contains the bookmark. - Or, in the macro, insert new code before and after the InsertBefore line like this: If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "0000#") ActiveDocument.Protect ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") That will turn off the protection just long enough to insert the sequence number, and then turn the protection on again. -- 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. snulton wrote: I now recieve a Run-time error `4605` This method or property is not available because the object refers to a protected area of the document. "Jay Freedman" wrote: That error is telling you that VBA couldn't find any bookmark named "Order" in your document. Look again at the article -- the second paragraph begins "In the template from which you create the document, insert a bookmark named Order in the location where you want the sequential number to appear." snulton wrote: I have almost completely started over due to receiving a Microsoft Visual Basic Run-time error `5941' The requested memer of the collection does not exist. When I click on the Debug button the line reading ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "00#") is hi-lited. "Jay Freedman" wrote: Hi Scott, In VBA, every "Sub" statement must have a matching "End Sub" statement, with all the commands of the macro in between. You have a "Sub MAIN()" statement without any matching "End Sub". Delete the "Sub Main()" line (and optionally also delete the four lines of comments that follow it). Then the "Sub AutoNew()" will match the "End Sub" at the bottom of the code, and that should stop the error message. snulton wrote: 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. |
#21
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
I get an error messege that I will be able to retrieve on monday to send to
you. Have a great weekend. :-} "snulton" wrote: Yes, each is a different template for a different kind of Word document. Sorry to be so dense, but could you give me an example of the different names? I am not sure that I understand. Is there something that I could download that explains it so I don't bother you further? "Jay Freedman" wrote: First, you have to use a different template for each sequence. Since you're doing forms of different kinds, I assume that's already true. Then the other part is to visit the macro code in each template and put in a different name for the file that stores the current number. Now they all say "C:\Settings.Txt" in two place (at least I hope they do -- the code you posted before has "C:\.txt" in the second place, which is wrong). On Thu, 18 Oct 2007 14:34:00 -0700, snulton wrote: Thank you! One more thing, how do I have different documents have their own sets of sequencial numbers? Right now the sequence is working but I am using the same "Order" in four different documents, two different contracts, one bid proposal and one invoice. "Jay Freedman" wrote: You can do either of two things: - In the template, insert continuous-type section breaks before and after the paragraph containing the bookmark. When you protect the document (using the Tools Protect Document menu item, not the lock icon on the Forms toolbar), click the "Select sections" link and uncheck the section that contains the bookmark. - Or, in the macro, insert new code before and after the InsertBefore line like this: If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "0000#") ActiveDocument.Protect ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") That will turn off the protection just long enough to insert the sequence number, and then turn the protection on again. -- 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. snulton wrote: I now recieve a Run-time error `4605` This method or property is not available because the object refers to a protected area of the document. "Jay Freedman" wrote: That error is telling you that VBA couldn't find any bookmark named "Order" in your document. Look again at the article -- the second paragraph begins "In the template from which you create the document, insert a bookmark named Order in the location where you want the sequential number to appear." snulton wrote: I have almost completely started over due to receiving a Microsoft Visual Basic Run-time error `5941' The requested memer of the collection does not exist. When I click on the Debug button the line reading ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "00#") is hi-lited. "Jay Freedman" wrote: Hi Scott, In VBA, every "Sub" statement must have a matching "End Sub" statement, with all the commands of the macro in between. You have a "Sub MAIN()" statement without any matching "End Sub". Delete the "Sub Main()" line (and optionally also delete the four lines of comments that follow it). Then the "Sub AutoNew()" will match the "End Sub" at the bottom of the code, and that should stop the error message. snulton wrote: 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. |
#22
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
I have tried to set up each of three different contracts that I have set as
templates (.dot) as individually numbered documents using the names for "NRS RemContract.dot" with the Order Macro set as below, with a new Macro named as RemContractOrder (replacing "Order" with "RemContractOrder") and nothing seems to work to give me a different numbering system for my three templates. The templates are named; NRS RemContract.dot, NRS Service & Repair.dot, and NRS Bid-proposal.dot. Please help a dumb Remodeling Contractor get this right. "Jay Freedman" wrote: Yes, that's correct. :-) snulton wrote: If I have it correctly, then: If the original Macro that you showed me: Sub AutoNew() Order = System.PrivateProfileString("C:\Settings.Txt","Mac roSettings","Order) If Order = "" Then Order = 1 Else Order = Order + 1 End If System.PrivateProfileString("C:\Settings.txt", "MacroSettings,"Order") = Order ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order. "0000#") ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") End Sub Then the modification would be: Sub AutoNew() Order = System.PrivateProfileString("C:\RemContract Sequence.Txt","MacroSettings","Order) If Order = "" Then Order = 1 Else Order = Order + 1 End If System.PrivateProfileString("C:\RemContract Sequence.Txt","MacroSettings","Order) = Order ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order. "0000#") ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") End Sub Is this correct? "Jay Freedman" wrote: No download, you're off in an area that's sort of "you just need to understand what you're doing". :-) Exactly what you use for the names isn't terribly important as long as (a) they're valid file names, (b) there's a different one for each template, and (c) you can recognize them when you see them. So I'll suggest that for each one you take the name of the template (assuming that's something you recognize as being associated with that type of form), add the word "sequence" and the extension ".txt". For example, if you have a template named "Contract A.dot" and one named "Contract B.dot", then the corresponding names inside the macro could be "Contract A sequence.txt" and "Contract B sequence.txt". Put a valid path in front of each name, for example "C:\Contract A sequence.txt", and put that into the macro in the template for Contract A. Put "C:\Contract B sequence.txt" into the macro in the template for Contract B. Do similarly for the other templates -- each one gets a filename in its macro that corresponds to that template only. Am I making sense yet? snulton wrote: Yes, each is a different template for a different kind of Word document. Sorry to be so dense, but could you give me an example of the different names? I am not sure that I understand. Is there something that I could download that explains it so I don't bother you further? "Jay Freedman" wrote: First, you have to use a different template for each sequence. Since you're doing forms of different kinds, I assume that's already true. Then the other part is to visit the macro code in each template and put in a different name for the file that stores the current number. Now they all say "C:\Settings.Txt" in two place (at least I hope they do -- the code you posted before has "C:\.txt" in the second place, which is wrong). On Thu, 18 Oct 2007 14:34:00 -0700, snulton wrote: Thank you! One more thing, how do I have different documents have their own sets of sequencial numbers? Right now the sequence is working but I am using the same "Order" in four different documents, two different contracts, one bid proposal and one invoice. "Jay Freedman" wrote: You can do either of two things: - In the template, insert continuous-type section breaks before and after the paragraph containing the bookmark. When you protect the document (using the Tools Protect Document menu item, not the lock icon on the Forms toolbar), click the "Select sections" link and uncheck the section that contains the bookmark. - Or, in the macro, insert new code before and after the InsertBefore line like this: If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "0000#") ActiveDocument.Protect ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") That will turn off the protection just long enough to insert the sequence number, and then turn the protection on again. -- 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. snulton wrote: I now recieve a Run-time error `4605` This method or property is not available because the object refers to a protected area of the document. "Jay Freedman" wrote: That error is telling you that VBA couldn't find any bookmark named "Order" in your document. Look again at the article -- the second paragraph begins "In the template from which you create the document, insert a bookmark named Order in the location where you want the sequential number to appear." snulton wrote: I have almost completely started over due to receiving a Microsoft Visual Basic Run-time error `5941' The requested memer of the collection does not exist. When I click on the Debug button the line reading ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "00#") is hi-lited. "Jay Freedman" wrote: Hi Scott, In VBA, every "Sub" statement must have a matching "End Sub" statement, with all the commands of the macro in between. You have a "Sub MAIN()" statement without any matching "End Sub". Delete the "Sub Main()" line (and optionally also delete the four lines of comments that follow it). Then the "Sub AutoNew()" will match the "End Sub" at the bottom of the code, and that should stop the error message. snulton wrote: 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 |
#23
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
Item 1: DO NOT change the name of the macro. It has to be named
AutoNew() in order to work. Item 2: In the template named "NRS RemContract.dot", there should be an AutoNew macro that contains the lines (each of these should be one line, but the posting program breaks them): Order = System.PrivateProfileString("C:\NRS RemContract Sequence.Txt","MacroSettings","Order) and System.PrivateProfileString("C:\NRS RemContract Sequence.Txt","MacroSettings","Order) = Order In the template named "NRS Service & Repair.dot", there should also be a macro named AutoNew, and it should contain the lines Order = System.PrivateProfileString("C:\NRS Service & Repair Sequence.Txt","MacroSettings","Order) and System.PrivateProfileString("C:\NRS Service & Repair Sequence.Txt","MacroSettings","Order) = Order In the template named "NRS Bid-proposal.dot", there should also be a macro named AutoNew, and it should contain the lines Order = System.PrivateProfileString("C:\NRS Bid-proposal Sequence.Txt","MacroSettings","Order) and System.PrivateProfileString("C:\NRS Bid-proposal Sequence.Txt","MacroSettings","Order) = Order Item 3: (Just in case you aren't already doing this...) You have to use the File New command (and if you get a task pane, click the link for "On my computer") and select the proper template as the base for a new document. The File New command is what causes the macro named AutoNew to run, and that does all the sequence number stuff. If you don't do File New, the macro doesn't run and you don't get a sequence number. Are we there yet? ;-) On Mon, 22 Oct 2007 16:11:01 -0700, snulton wrote: I have tried to set up each of three different contracts that I have set as templates (.dot) as individually numbered documents using the names for "NRS RemContract.dot" with the Order Macro set as below, with a new Macro named as RemContractOrder (replacing "Order" with "RemContractOrder") and nothing seems to work to give me a different numbering system for my three templates. The templates are named; NRS RemContract.dot, NRS Service & Repair.dot, and NRS Bid-proposal.dot. Please help a dumb Remodeling Contractor get this right. "Jay Freedman" wrote: Yes, that's correct. :-) snulton wrote: If I have it correctly, then: If the original Macro that you showed me: Sub AutoNew() Order = System.PrivateProfileString("C:\Settings.Txt","Mac roSettings","Order) If Order = "" Then Order = 1 Else Order = Order + 1 End If System.PrivateProfileString("C:\Settings.txt", "MacroSettings,"Order") = Order ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order. "0000#") ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") End Sub Then the modification would be: Sub AutoNew() Order = System.PrivateProfileString("C:\RemContract Sequence.Txt","MacroSettings","Order) If Order = "" Then Order = 1 Else Order = Order + 1 End If System.PrivateProfileString("C:\RemContract Sequence.Txt","MacroSettings","Order) = Order ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order. "0000#") ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") End Sub Is this correct? "Jay Freedman" wrote: No download, you're off in an area that's sort of "you just need to understand what you're doing". :-) Exactly what you use for the names isn't terribly important as long as (a) they're valid file names, (b) there's a different one for each template, and (c) you can recognize them when you see them. So I'll suggest that for each one you take the name of the template (assuming that's something you recognize as being associated with that type of form), add the word "sequence" and the extension ".txt". For example, if you have a template named "Contract A.dot" and one named "Contract B.dot", then the corresponding names inside the macro could be "Contract A sequence.txt" and "Contract B sequence.txt". Put a valid path in front of each name, for example "C:\Contract A sequence.txt", and put that into the macro in the template for Contract A. Put "C:\Contract B sequence.txt" into the macro in the template for Contract B. Do similarly for the other templates -- each one gets a filename in its macro that corresponds to that template only. Am I making sense yet? snulton wrote: Yes, each is a different template for a different kind of Word document. Sorry to be so dense, but could you give me an example of the different names? I am not sure that I understand. Is there something that I could download that explains it so I don't bother you further? "Jay Freedman" wrote: First, you have to use a different template for each sequence. Since you're doing forms of different kinds, I assume that's already true. Then the other part is to visit the macro code in each template and put in a different name for the file that stores the current number. Now they all say "C:\Settings.Txt" in two place (at least I hope they do -- the code you posted before has "C:\.txt" in the second place, which is wrong). On Thu, 18 Oct 2007 14:34:00 -0700, snulton wrote: Thank you! One more thing, how do I have different documents have their own sets of sequencial numbers? Right now the sequence is working but I am using the same "Order" in four different documents, two different contracts, one bid proposal and one invoice. "Jay Freedman" wrote: You can do either of two things: - In the template, insert continuous-type section breaks before and after the paragraph containing the bookmark. When you protect the document (using the Tools Protect Document menu item, not the lock icon on the Forms toolbar), click the "Select sections" link and uncheck the section that contains the bookmark. - Or, in the macro, insert new code before and after the InsertBefore line like this: If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "0000#") ActiveDocument.Protect ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") That will turn off the protection just long enough to insert the sequence number, and then turn the protection on again. -- 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. snulton wrote: I now recieve a Run-time error `4605` This method or property is not available because the object refers to a protected area of the document. "Jay Freedman" wrote: That error is telling you that VBA couldn't find any bookmark named "Order" in your document. Look again at the article -- the second paragraph begins "In the template from which you create the document, insert a bookmark named Order in the location where you want the sequential number to appear." snulton wrote: I have almost completely started over due to receiving a Microsoft Visual Basic Run-time error `5941' The requested memer of the collection does not exist. When I click on the Debug button the line reading ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "00#") is hi-lited. "Jay Freedman" wrote: Hi Scott, In VBA, every "Sub" statement must have a matching "End Sub" statement, with all the commands of the macro in between. You have a "Sub MAIN()" statement without any matching "End Sub". Delete the "Sub Main()" line (and optionally also delete the four lines of comments that follow it). Then the "Sub AutoNew()" will match the "End Sub" at the bottom of the code, and that should stop the error message. snulton wrote: 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 -- 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. |
#24
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
I followed the items you laid out and when I open the next template to modify
it the AutoNew is already set. When I make the modifications to that Macro for the open document, it resets all the other templates to that sequential numbering. As per Item 3: I hadn't been doing that but even when I do I get the sequence of numbers that is continuos no matter which template I open If I open one template that has a number of 01005, then open a different template that is suposed to have a number starting 03*** it will open with 01006. Although all these are separate templates, the AutoNew seems to treat them the same. when I attempt to set the AutoNew for a specific template and I edit what is opened with AutoNew to reflect that template it changes all the other templates to that Macro. "Jay Freedman" wrote: Item 1: DO NOT change the name of the macro. It has to be named AutoNew() in order to work. Item 2: In the template named "NRS RemContract.dot", there should be an AutoNew macro that contains the lines (each of these should be one line, but the posting program breaks them): Order = System.PrivateProfileString("C:\NRS RemContract Sequence.Txt","MacroSettings","Order) and System.PrivateProfileString("C:\NRS RemContract Sequence.Txt","MacroSettings","Order) = Order In the template named "NRS Service & Repair.dot", there should also be a macro named AutoNew, and it should contain the lines Order = System.PrivateProfileString("C:\NRS Service & Repair Sequence.Txt","MacroSettings","Order) and System.PrivateProfileString("C:\NRS Service & Repair Sequence.Txt","MacroSettings","Order) = Order In the template named "NRS Bid-proposal.dot", there should also be a macro named AutoNew, and it should contain the lines Order = System.PrivateProfileString("C:\NRS Bid-proposal Sequence.Txt","MacroSettings","Order) and System.PrivateProfileString("C:\NRS Bid-proposal Sequence.Txt","MacroSettings","Order) = Order Item 3: (Just in case you aren't already doing this...) You have to use the File New command (and if you get a task pane, click the link for "On my computer") and select the proper template as the base for a new document. The File New command is what causes the macro named AutoNew to run, and that does all the sequence number stuff. If you don't do File New, the macro doesn't run and you don't get a sequence number. Are we there yet? ;-) On Mon, 22 Oct 2007 16:11:01 -0700, snulton wrote: I have tried to set up each of three different contracts that I have set as templates (.dot) as individually numbered documents using the names for "NRS RemContract.dot" with the Order Macro set as below, with a new Macro named as RemContractOrder (replacing "Order" with "RemContractOrder") and nothing seems to work to give me a different numbering system for my three templates. The templates are named; NRS RemContract.dot, NRS Service & Repair.dot, and NRS Bid-proposal.dot. Please help a dumb Remodeling Contractor get this right. "Jay Freedman" wrote: Yes, that's correct. :-) snulton wrote: If I have it correctly, then: If the original Macro that you showed me: Sub AutoNew() Order = System.PrivateProfileString("C:\Settings.Txt","Mac roSettings","Order) If Order = "" Then Order = 1 Else Order = Order + 1 End If System.PrivateProfileString("C:\Settings.txt", "MacroSettings,"Order") = Order ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order. "0000#") ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") End Sub Then the modification would be: Sub AutoNew() Order = System.PrivateProfileString("C:\RemContract Sequence.Txt","MacroSettings","Order) If Order = "" Then Order = 1 Else Order = Order + 1 End If System.PrivateProfileString("C:\RemContract Sequence.Txt","MacroSettings","Order) = Order ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order. "0000#") ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") End Sub Is this correct? "Jay Freedman" wrote: No download, you're off in an area that's sort of "you just need to understand what you're doing". :-) Exactly what you use for the names isn't terribly important as long as (a) they're valid file names, (b) there's a different one for each template, and (c) you can recognize them when you see them. So I'll suggest that for each one you take the name of the template (assuming that's something you recognize as being associated with that type of form), add the word "sequence" and the extension ".txt". For example, if you have a template named "Contract A.dot" and one named "Contract B.dot", then the corresponding names inside the macro could be "Contract A sequence.txt" and "Contract B sequence.txt". Put a valid path in front of each name, for example "C:\Contract A sequence.txt", and put that into the macro in the template for Contract A. Put "C:\Contract B sequence.txt" into the macro in the template for Contract B. Do similarly for the other templates -- each one gets a filename in its macro that corresponds to that template only. Am I making sense yet? snulton wrote: Yes, each is a different template for a different kind of Word document. Sorry to be so dense, but could you give me an example of the different names? I am not sure that I understand. Is there something that I could download that explains it so I don't bother you further? "Jay Freedman" wrote: First, you have to use a different template for each sequence. Since you're doing forms of different kinds, I assume that's already true. Then the other part is to visit the macro code in each template and put in a different name for the file that stores the current number. Now they all say "C:\Settings.Txt" in two place (at least I hope they do -- the code you posted before has "C:\.txt" in the second place, which is wrong). On Thu, 18 Oct 2007 14:34:00 -0700, snulton wrote: Thank you! One more thing, how do I have different documents have their own sets of sequencial numbers? Right now the sequence is working but I am using the same "Order" in four different documents, two different contracts, one bid proposal and one invoice. "Jay Freedman" wrote: You can do either of two things: - In the template, insert continuous-type section breaks before and after the paragraph containing the bookmark. When you protect the document (using the Tools Protect Document menu item, not the lock icon on the Forms toolbar), click the "Select sections" link and uncheck the section that contains the bookmark. - Or, in the macro, insert new code before and after the InsertBefore line like this: If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "0000#") ActiveDocument.Protect ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") That will turn off the protection just long enough to insert the sequence number, and then turn the protection on again. -- 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. snulton wrote: I now recieve a Run-time error `4605` This method or property is not available because the object refers to a protected area of the document. "Jay Freedman" wrote: That error is telling you that VBA couldn't find any bookmark named "Order" in your document. Look again at the article -- the second paragraph begins "In the template from which you create the document, insert a bookmark named Order in the location where you want the sequential number to appear." snulton wrote: I have almost completely started over due to receiving a Microsoft Visual Basic Run-time error `5941' The requested memer of the collection does not exist. When I click on the Debug button the line reading ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "00#") is hi-lited. "Jay Freedman" wrote: Hi Scott, In VBA, every "Sub" statement must have a matching "End Sub" statement, with all the commands of the macro in between. You have a "Sub MAIN()" statement without any matching "End Sub". Delete the "Sub Main()" line (and optionally also delete the four lines of comments that follow it). Then the "Sub AutoNew()" will match the "End Sub" at the bottom of the code, and that should stop the error message. snulton wrote: 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 |
#25
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
when I attempt to set the AutoNew for a specific
template and I edit what is opened with AutoNew to reflect that template it changes all the other templates to that Macro. That _should_ be impossible, if you're working correctly in the VBA editor. In the VBA editor, there should be a panel on the left side, titled Project. (If you don't see it, click View Project Explorer or press the shortcut Ctrl+R). It's a tree diagram that shows open templates and documents as folders, labeled as "Project" or "TemplateProject" plus the name of the file it represents. Expand the icon (by clicking the plus sign) for the particular template you're working on, and you should see a "Microsoft Word Objects" folder and a "Modules" folder. Expand the "Modules" folder, and under that you should see at least one item, possibly named "Module1" or "NewMacros" or something else. When you double-click this module, you should see the AutoNew code in the big window on the right. If you don't see what I just described, then the AutoNew macro is probably in a module under the Modules folder in the Normal project, which represents the Normal.dot template. THAT'S THE WRONG PLACE. A module in the Normal.dot template is NOT in the other templates. The Normal.dot template loads when Word starts, and its macros are available in every document regardless of what template the document is based on, so an AutoNew in Normal "appears" to be present for every template. But that's not what you want -- you want a separate AutoNew in each of your templates and NONE in Normal.dot. If that's where it is, follow these steps: - Click (to select) the "Modules" folder under the form template you're working on (for example, "NRS RemContract.dot"). - On the VBA Editor menu, click Insert Module. Notice the new module icon in the tree diagram. - Double-click the module under the Normal project that contains the AutoNew macro code. Select that code and cut it to the clipboard. You don't want to leave any AutoNew code in the Normal template. - Double-click the module icon you created in the tree under your template's icon. Paste the code from the clipboard into the big empty window on the right. - Make sure the file names we've been discussing match the name of the template you're working with. - Click the Save toolbar button, which saves this template. - Close your template and try using File New. Remember, File New is necessary to run the AutoNew macro. Now you should be able to open another of your templates, create a module under its project icon, paste in a copy of the code, change the file names, and save. That should operate independently of the first template. snulton wrote: I followed the items you laid out and when I open the next template to modify it the AutoNew is already set. When I make the modifications to that Macro for the open document, it resets all the other templates to that sequential numbering. As per Item 3: I hadn't been doing that but even when I do I get the sequence of numbers that is continuos no matter which template I open If I open one template that has a number of 01005, then open a different template that is suposed to have a number starting 03*** it will open with 01006. Although all these are separate templates, the AutoNew seems to treat them the same. when I attempt to set the AutoNew for a specific template and I edit what is opened with AutoNew to reflect that template it changes all the other templates to that Macro. "Jay Freedman" wrote: Item 1: DO NOT change the name of the macro. It has to be named AutoNew() in order to work. Item 2: In the template named "NRS RemContract.dot", there should be an AutoNew macro that contains the lines (each of these should be one line, but the posting program breaks them): Order = System.PrivateProfileString("C:\NRS RemContract Sequence.Txt","MacroSettings","Order) and System.PrivateProfileString("C:\NRS RemContract Sequence.Txt","MacroSettings","Order) = Order In the template named "NRS Service & Repair.dot", there should also be a macro named AutoNew, and it should contain the lines Order = System.PrivateProfileString("C:\NRS Service & Repair Sequence.Txt","MacroSettings","Order) and System.PrivateProfileString("C:\NRS Service & Repair Sequence.Txt","MacroSettings","Order) = Order In the template named "NRS Bid-proposal.dot", there should also be a macro named AutoNew, and it should contain the lines Order = System.PrivateProfileString("C:\NRS Bid-proposal Sequence.Txt","MacroSettings","Order) and System.PrivateProfileString("C:\NRS Bid-proposal Sequence.Txt","MacroSettings","Order) = Order Item 3: (Just in case you aren't already doing this...) You have to use the File New command (and if you get a task pane, click the link for "On my computer") and select the proper template as the base for a new document. The File New command is what causes the macro named AutoNew to run, and that does all the sequence number stuff. If you don't do File New, the macro doesn't run and you don't get a sequence number. Are we there yet? ;-) On Mon, 22 Oct 2007 16:11:01 -0700, snulton wrote: I have tried to set up each of three different contracts that I have set as templates (.dot) as individually numbered documents using the names for "NRS RemContract.dot" with the Order Macro set as below, with a new Macro named as RemContractOrder (replacing "Order" with "RemContractOrder") and nothing seems to work to give me a different numbering system for my three templates. The templates are named; NRS RemContract.dot, NRS Service & Repair.dot, and NRS Bid-proposal.dot. Please help a dumb Remodeling Contractor get this right. "Jay Freedman" wrote: Yes, that's correct. :-) snulton wrote: If I have it correctly, then: If the original Macro that you showed me: Sub AutoNew() Order = System.PrivateProfileString("C:\Settings.Txt","Mac roSettings","Order) If Order = "" Then Order = 1 Else Order = Order + 1 End If System.PrivateProfileString("C:\Settings.txt", "MacroSettings,"Order") = Order ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order. "0000#") ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") End Sub Then the modification would be: Sub AutoNew() Order = System.PrivateProfileString("C:\RemContract Sequence.Txt","MacroSettings","Order) If Order = "" Then Order = 1 Else Order = Order + 1 End If System.PrivateProfileString("C:\RemContract Sequence.Txt","MacroSettings","Order) = Order ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order. "0000#") ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") End Sub Is this correct? "Jay Freedman" wrote: No download, you're off in an area that's sort of "you just need to understand what you're doing". :-) Exactly what you use for the names isn't terribly important as long as (a) they're valid file names, (b) there's a different one for each template, and (c) you can recognize them when you see them. So I'll suggest that for each one you take the name of the template (assuming that's something you recognize as being associated with that type of form), add the word "sequence" and the extension ".txt". For example, if you have a template named "Contract A.dot" and one named "Contract B.dot", then the corresponding names inside the macro could be "Contract A sequence.txt" and "Contract B sequence.txt". Put a valid path in front of each name, for example "C:\Contract A sequence.txt", and put that into the macro in the template for Contract A. Put "C:\Contract B sequence.txt" into the macro in the template for Contract B. Do similarly for the other templates -- each one gets a filename in its macro that corresponds to that template only. Am I making sense yet? snulton wrote: Yes, each is a different template for a different kind of Word document. Sorry to be so dense, but could you give me an example of the different names? I am not sure that I understand. Is there something that I could download that explains it so I don't bother you further? "Jay Freedman" wrote: First, you have to use a different template for each sequence. Since you're doing forms of different kinds, I assume that's already true. Then the other part is to visit the macro code in each template and put in a different name for the file that stores the current number. Now they all say "C:\Settings.Txt" in two place (at least I hope they do -- the code you posted before has "C:\.txt" in the second place, which is wrong). On Thu, 18 Oct 2007 14:34:00 -0700, snulton wrote: Thank you! One more thing, how do I have different documents have their own sets of sequencial numbers? Right now the sequence is working but I am using the same "Order" in four different documents, two different contracts, one bid proposal and one invoice. "Jay Freedman" wrote: You can do either of two things: - In the template, insert continuous-type section breaks before and after the paragraph containing the bookmark. When you protect the document (using the Tools Protect Document menu item, not the lock icon on the Forms toolbar), click the "Select sections" link and uncheck the section that contains the bookmark. - Or, in the macro, insert new code before and after the InsertBefore line like this: If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "0000#") ActiveDocument.Protect ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") That will turn off the protection just long enough to insert the sequence number, and then turn the protection on again. -- 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. snulton wrote: I now recieve a Run-time error `4605` This method or property is not available because the object refers to a protected area of the document. "Jay Freedman" wrote: That error is telling you that VBA couldn't find any bookmark named "Order" in your document. Look again at the article -- the second paragraph begins "In the template from which you create the document, insert a bookmark named Order in the location where you want the sequential number to appear." snulton wrote: I have almost completely started over due to receiving a Microsoft Visual Basic Run-time error `5941' The requested memer of the collection does not exist. When I click on the Debug button the line reading ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "00#") is hi-lited. "Jay Freedman" wrote: Hi Scott, In VBA, every "Sub" statement must have a matching "End Sub" statement, with all the commands of the macro in between. You have a "Sub MAIN()" statement without any matching "End Sub". Delete the "Sub Main()" line (and optionally also delete the four lines of comments that follow it). Then the "Sub AutoNew()" will match the "End Sub" at the bottom of the code, and that should stop the error message. snulton wrote: 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 |
#26
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
I hope that I didn't upset you with my insessent questions, but I am going
to repost this: I am probably beginning to sound really stupid. So let me see if I have it from the beginning. First I open a template (.dot) which automatically creates a document (.doc) that has a name "Document* (* = the number of the document opened and saved) then in that document I go to File New which opens a task pane that I then click on the Link for "On my Computer", I then receive a new Template (.dot) named "path0*****.dot, I then set my bookmark where I want the sequential numbers and then Go to Tools Macro Macros and am given a choice in the window that opens a blank space for Macro name, a bigger area that has AutoExec.MAIN, AutoExit.MAIN, and RunFineReader, with active buttons "Create", "Organizer", and "Close". Logic tells me that I would then "Create" AutoNew. This then opens Microsoft Visual Basic which has a panel that has a choice of "FineReader6SprintTools", "Normal", "Project (Document 1)" (with no modules), "TemplateProject (Live Meeting Toolbar Customizations)" and finally "TemplateProject (SerRepCon)" [the name of the original template], both the "Project (Document 1)" and the "TemplateProject (SerRepCon)" have "ThisDocument" when opening "Microsoft Word Objects". Which one do I use? The code window that opens caries the header of whichever main catagory is highlighted. This is the window that I put the AutoNew language. After this is done I would then click on the Save icon on the toolbar in Microsoft Visual Basic and shut window. then I would go to File SaveAs and name the document the same as the name used in the Macro before "sequence". Is this correct? Inf not Please correct within the messege. "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. |
#27
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
Hi Scott,
I'm not upset; this is a complicated setup. But it does seem that you missed some fundamental principles, and I'm glad of the chance to start at the bottom and clear things up. Your paragraph "First I open a template ..." is not correct. Please wipe that blackboard clean, and we'll start from the beginning. I'll assume you have a template named SerRepCon.dot that contains the text of a contract. Within that text are some form fields. For each customer, you want to make a document based on the template, in which the form fields will be filled in differently. Some place in the document you want to put a sequence number that will be different for each document, and that number will also become part of the document's file name. Right so far? I'll also assume that at this point the SerRepCon.dot template doesn't contain any macros, and that the template file is stored in your Templates folder (something like C:\Documents and Settings\snulton\Application Data\Microsoft\Templates). Start the Word program. Click File Open (_not_ File New at this time). Set the "Files of type" dropdown to "Document Templates (*.dot)". Use the "Look in" dropdown to navigate to the Templates folder, select SerRepCon.dot, and click OK. You're now able to edit the SerRepCon.dot template itself, not any document based on it. Put the cursor in the location where you want the sequence number to appear, and insert a bookmark named "Order". That same bookmark will automatically appear in each document you base on this template. Open the VBA editor. The Projects pane should include icons for Normal (because Normal.dot is always loaded), FineReader6SprintTools (which is an add-in from the FineReader program), Live Meeting Toolbar Customizations (another add-in), and SerRepCon. If you followed the directions exactly, there shouldn't be any others -- but if there are, ignore them. Select and expand the icon for "TemplateProject (SerRepCon)". It should contain a folder named "Microsoft Word Objects", in which there is a "ThisDocument" icon. Ignore those. Click the Insert Module command on the menu (in the VBA editor, not in Word's window). That will create a Modules folder under "TemplateProject (SerRepCon)", containing a "Module1" icon. To verify that you're in the right place, the code window should be empty and the title bar should say "Microsoft Visual Basic - SerRepCon - [Module1 (Code)]". Click in the code window and paste in the code of the AutoNew macro from our recent posts. Make sure it includes the lines to unprotect and reprotect the form. The two lines that mention System.PrivateProfileString should contain "C:\SerRepCon Sequence.txt" as the name of the file to contain the current sequence number. Close the VBA editor. Turn on form protection (click the lock icon on the Forms toolbar), save the template, and close it. Open the File New dialog (_not_ File Open -- now you're going to create a document based on the template). Select the SerRepCon template and click OK. You should see a document named "path00001.doc" that is a protected form with the sequence number 00001 at the place marked by the Order bookmark. Each time you go to File New and select the SerRepCon template as the basis for a new document, you should get another document and the sequence number should be greater by 1 than the one before. Now repeat all the previous steps for the template of another kind of form; the only difference should be that the lines that mention System.PrivateProfileString should contain the name of a different text file -- one related to that particular template. By the way, I don't think you really want the word "path" as part of the document's filename. The reason it's there now is that the original article on word.mvps.org shows it there -- but it was meant to represent the folder location (that is, the path from C:\ to the folder where you want the document to be stored), not the literal word "path". If you just want to store all the documents in the My Documents folder, you could change the Save statement to something like ActiveDocument.SaveAs FileName:="SerRepCon" & Format(Order, "0000#") so the actual name of a document based on this template would be something like SerRepCon00001.doc. Because the filename doesn't contain any information about the folder, Word automatically uses whatever folder you have set as the Documents location in the Tools Options File Locations dialog -- and by default that's the My Documents folder. -- 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. snulton wrote: I hope that I didn't upset you with my insessent questions, but I am going to repost this: I am probably beginning to sound really stupid. So let me see if I have it from the beginning. First I open a template (.dot) which automatically creates a document (.doc) that has a name "Document* (* = the number of the document opened and saved) then in that document I go to File New which opens a task pane that I then click on the Link for "On my Computer", I then receive a new Template (.dot) named "path0*****.dot, I then set my bookmark where I want the sequential numbers and then Go to Tools Macro Macros and am given a choice in the window that opens a blank space for Macro name, a bigger area that has AutoExec.MAIN, AutoExit.MAIN, and RunFineReader, with active buttons "Create", "Organizer", and "Close". Logic tells me that I would then "Create" AutoNew. This then opens Microsoft Visual Basic which has a panel that has a choice of "FineReader6SprintTools", "Normal", "Project (Document 1)" (with no modules), "TemplateProject (Live Meeting Toolbar Customizations)" and finally "TemplateProject (SerRepCon)" [the name of the original template], both the "Project (Document 1)" and the "TemplateProject (SerRepCon)" have "ThisDocument" when opening "Microsoft Word Objects". Which one do I use? The code window that opens caries the header of whichever main catagory is highlighted. This is the window that I put the AutoNew language. After this is done I would then click on the Save icon on the toolbar in Microsoft Visual Basic and shut window. then I would go to File SaveAs and name the document the same as the name used in the Macro before "sequence". Is this correct? Inf not Please correct within the messege. "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. |
#28
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
Thank you Jay;
I got it to work, however if the lock icon is clicked to protect the form when that template is accessed an Error messege: "Run-time error `4605` This method or property is not available because the object refers to a protected area of the document. appears. When clicking on "De-bug" The VBA opens the AutoNew window and highlites the second to last line before "End Sub" But without the document "protected" the numbering works. Thanks again "Jay Freedman" wrote: Hi Scott, I'm not upset; this is a complicated setup. But it does seem that you missed some fundamental principles, and I'm glad of the chance to start at the bottom and clear things up. Your paragraph "First I open a template ..." is not correct. Please wipe that blackboard clean, and we'll start from the beginning. I'll assume you have a template named SerRepCon.dot that contains the text of a contract. Within that text are some form fields. For each customer, you want to make a document based on the template, in which the form fields will be filled in differently. Some place in the document you want to put a sequence number that will be different for each document, and that number will also become part of the document's file name. Right so far? I'll also assume that at this point the SerRepCon.dot template doesn't contain any macros, and that the template file is stored in your Templates folder (something like C:\Documents and Settings\snulton\Application Data\Microsoft\Templates). Start the Word program. Click File Open (_not_ File New at this time). Set the "Files of type" dropdown to "Document Templates (*.dot)". Use the "Look in" dropdown to navigate to the Templates folder, select SerRepCon.dot, and click OK. You're now able to edit the SerRepCon.dot template itself, not any document based on it. Put the cursor in the location where you want the sequence number to appear, and insert a bookmark named "Order". That same bookmark will automatically appear in each document you base on this template. Open the VBA editor. The Projects pane should include icons for Normal (because Normal.dot is always loaded), FineReader6SprintTools (which is an add-in from the FineReader program), Live Meeting Toolbar Customizations (another add-in), and SerRepCon. If you followed the directions exactly, there shouldn't be any others -- but if there are, ignore them. Select and expand the icon for "TemplateProject (SerRepCon)". It should contain a folder named "Microsoft Word Objects", in which there is a "ThisDocument" icon. Ignore those. Click the Insert Module command on the menu (in the VBA editor, not in Word's window). That will create a Modules folder under "TemplateProject (SerRepCon)", containing a "Module1" icon. To verify that you're in the right place, the code window should be empty and the title bar should say "Microsoft Visual Basic - SerRepCon - [Module1 (Code)]". Click in the code window and paste in the code of the AutoNew macro from our recent posts. Make sure it includes the lines to unprotect and reprotect the form. The two lines that mention System.PrivateProfileString should contain "C:\SerRepCon Sequence.txt" as the name of the file to contain the current sequence number. Close the VBA editor. Turn on form protection (click the lock icon on the Forms toolbar), save the template, and close it. Open the File New dialog (_not_ File Open -- now you're going to create a document based on the template). Select the SerRepCon template and click OK. You should see a document named "path00001.doc" that is a protected form with the sequence number 00001 at the place marked by the Order bookmark. Each time you go to File New and select the SerRepCon template as the basis for a new document, you should get another document and the sequence number should be greater by 1 than the one before. Now repeat all the previous steps for the template of another kind of form; the only difference should be that the lines that mention System.PrivateProfileString should contain the name of a different text file -- one related to that particular template. By the way, I don't think you really want the word "path" as part of the document's filename. The reason it's there now is that the original article on word.mvps.org shows it there -- but it was meant to represent the folder location (that is, the path from C:\ to the folder where you want the document to be stored), not the literal word "path". If you just want to store all the documents in the My Documents folder, you could change the Save statement to something like ActiveDocument.SaveAs FileName:="SerRepCon" & Format(Order, "0000#") so the actual name of a document based on this template would be something like SerRepCon00001.doc. Because the filename doesn't contain any information about the folder, Word automatically uses whatever folder you have set as the Documents location in the Tools Options File Locations dialog -- and by default that's the My Documents folder. -- 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. snulton wrote: I hope that I didn't upset you with my insessent questions, but I am going to repost this: I am probably beginning to sound really stupid. So let me see if I have it from the beginning. First I open a template (.dot) which automatically creates a document (.doc) that has a name "Document* (* = the number of the document opened and saved) then in that document I go to File New which opens a task pane that I then click on the Link for "On my Computer", I then receive a new Template (.dot) named "path0*****.dot, I then set my bookmark where I want the sequential numbers and then Go to Tools Macro Macros and am given a choice in the window that opens a blank space for Macro name, a bigger area that has AutoExec.MAIN, AutoExit.MAIN, and RunFineReader, with active buttons "Create", "Organizer", and "Close". Logic tells me that I would then "Create" AutoNew. This then opens Microsoft Visual Basic which has a panel that has a choice of "FineReader6SprintTools", "Normal", "Project (Document 1)" (with no modules), "TemplateProject (Live Meeting Toolbar Customizations)" and finally "TemplateProject (SerRepCon)" [the name of the original template], both the "Project (Document 1)" and the "TemplateProject (SerRepCon)" have "ThisDocument" when opening "Microsoft Word Objects". Which one do I use? The code window that opens caries the header of whichever main catagory is highlighted. This is the window that I put the AutoNew language. After this is done I would then click on the Save icon on the toolbar in Microsoft Visual Basic and shut window. then I would go to File SaveAs and name the document the same as the name used in the Macro before "sequence". Is this correct? Inf not Please correct within the messege. "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. |
#29
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
Did you include the code to unprotect the document and the code to protect
the document? This was in my post of 10/182007: - ... insert new code before and after the InsertBefore line like this: If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "0000#") ActiveDocument.Protect ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") That will turn off the protection just long enough to insert the sequence number, and then turn the protection on again. -- 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. snulton wrote: Thank you Jay; I got it to work, however if the lock icon is clicked to protect the form when that template is accessed an Error messege: "Run-time error `4605` This method or property is not available because the object refers to a protected area of the document. appears. When clicking on "De-bug" The VBA opens the AutoNew window and highlites the second to last line before "End Sub" But without the document "protected" the numbering works. Thanks again "Jay Freedman" wrote: Hi Scott, I'm not upset; this is a complicated setup. But it does seem that you missed some fundamental principles, and I'm glad of the chance to start at the bottom and clear things up. Your paragraph "First I open a template ..." is not correct. Please wipe that blackboard clean, and we'll start from the beginning. I'll assume you have a template named SerRepCon.dot that contains the text of a contract. Within that text are some form fields. For each customer, you want to make a document based on the template, in which the form fields will be filled in differently. Some place in the document you want to put a sequence number that will be different for each document, and that number will also become part of the document's file name. Right so far? I'll also assume that at this point the SerRepCon.dot template doesn't contain any macros, and that the template file is stored in your Templates folder (something like C:\Documents and Settings\snulton\Application Data\Microsoft\Templates). Start the Word program. Click File Open (_not_ File New at this time). Set the "Files of type" dropdown to "Document Templates (*.dot)". Use the "Look in" dropdown to navigate to the Templates folder, select SerRepCon.dot, and click OK. You're now able to edit the SerRepCon.dot template itself, not any document based on it. Put the cursor in the location where you want the sequence number to appear, and insert a bookmark named "Order". That same bookmark will automatically appear in each document you base on this template. Open the VBA editor. The Projects pane should include icons for Normal (because Normal.dot is always loaded), FineReader6SprintTools (which is an add-in from the FineReader program), Live Meeting Toolbar Customizations (another add-in), and SerRepCon. If you followed the directions exactly, there shouldn't be any others -- but if there are, ignore them. Select and expand the icon for "TemplateProject (SerRepCon)". It should contain a folder named "Microsoft Word Objects", in which there is a "ThisDocument" icon. Ignore those. Click the Insert Module command on the menu (in the VBA editor, not in Word's window). That will create a Modules folder under "TemplateProject (SerRepCon)", containing a "Module1" icon. To verify that you're in the right place, the code window should be empty and the title bar should say "Microsoft Visual Basic - SerRepCon - [Module1 (Code)]". Click in the code window and paste in the code of the AutoNew macro from our recent posts. Make sure it includes the lines to unprotect and reprotect the form. The two lines that mention System.PrivateProfileString should contain "C:\SerRepCon Sequence.txt" as the name of the file to contain the current sequence number. Close the VBA editor. Turn on form protection (click the lock icon on the Forms toolbar), save the template, and close it. Open the File New dialog (_not_ File Open -- now you're going to create a document based on the template). Select the SerRepCon template and click OK. You should see a document named "path00001.doc" that is a protected form with the sequence number 00001 at the place marked by the Order bookmark. Each time you go to File New and select the SerRepCon template as the basis for a new document, you should get another document and the sequence number should be greater by 1 than the one before. Now repeat all the previous steps for the template of another kind of form; the only difference should be that the lines that mention System.PrivateProfileString should contain the name of a different text file -- one related to that particular template. By the way, I don't think you really want the word "path" as part of the document's filename. The reason it's there now is that the original article on word.mvps.org shows it there -- but it was meant to represent the folder location (that is, the path from C:\ to the folder where you want the document to be stored), not the literal word "path". If you just want to store all the documents in the My Documents folder, you could change the Save statement to something like ActiveDocument.SaveAs FileName:="SerRepCon" & Format(Order, "0000#") so the actual name of a document based on this template would be something like SerRepCon00001.doc. Because the filename doesn't contain any information about the folder, Word automatically uses whatever folder you have set as the Documents location in the Tools Options File Locations dialog -- and by default that's the My Documents folder. -- 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. snulton wrote: I hope that I didn't upset you with my insessent questions, but I am going to repost this: I am probably beginning to sound really stupid. So let me see if I have it from the beginning. First I open a template (.dot) which automatically creates a document (.doc) that has a name "Document* (* = the number of the document opened and saved) then in that document I go to File New which opens a task pane that I then click on the Link for "On my Computer", I then receive a new Template (.dot) named "path0*****.dot, I then set my bookmark where I want the sequential numbers and then Go to Tools Macro Macros and am given a choice in the window that opens a blank space for Macro name, a bigger area that has AutoExec.MAIN, AutoExit.MAIN, and RunFineReader, with active buttons "Create", "Organizer", and "Close". Logic tells me that I would then "Create" AutoNew. This then opens Microsoft Visual Basic which has a panel that has a choice of "FineReader6SprintTools", "Normal", "Project (Document 1)" (with no modules), "TemplateProject (Live Meeting Toolbar Customizations)" and finally "TemplateProject (SerRepCon)" [the name of the original template], both the "Project (Document 1)" and the "TemplateProject (SerRepCon)" have "ThisDocument" when opening "Microsoft Word Objects". Which one do I use? The code window that opens caries the header of whichever main catagory is highlighted. This is the window that I put the AutoNew language. After this is done I would then click on the Save icon on the toolbar in Microsoft Visual Basic and shut window. then I would go to File SaveAs and name the document the same as the name used in the Macro before "sequence". Is this correct? Inf not Please correct within the messege. "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. |
#30
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
OOPS!!! :-}
"Jay Freedman" wrote: Did you include the code to unprotect the document and the code to protect the document? This was in my post of 10/182007: - ... insert new code before and after the InsertBefore line like this: If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "0000#") ActiveDocument.Protect ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") That will turn off the protection just long enough to insert the sequence number, and then turn the protection on again. -- 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. snulton wrote: Thank you Jay; I got it to work, however if the lock icon is clicked to protect the form when that template is accessed an Error messege: "Run-time error `4605` This method or property is not available because the object refers to a protected area of the document. appears. When clicking on "De-bug" The VBA opens the AutoNew window and highlites the second to last line before "End Sub" But without the document "protected" the numbering works. Thanks again "Jay Freedman" wrote: Hi Scott, I'm not upset; this is a complicated setup. But it does seem that you missed some fundamental principles, and I'm glad of the chance to start at the bottom and clear things up. Your paragraph "First I open a template ..." is not correct. Please wipe that blackboard clean, and we'll start from the beginning. I'll assume you have a template named SerRepCon.dot that contains the text of a contract. Within that text are some form fields. For each customer, you want to make a document based on the template, in which the form fields will be filled in differently. Some place in the document you want to put a sequence number that will be different for each document, and that number will also become part of the document's file name. Right so far? I'll also assume that at this point the SerRepCon.dot template doesn't contain any macros, and that the template file is stored in your Templates folder (something like C:\Documents and Settings\snulton\Application Data\Microsoft\Templates). Start the Word program. Click File Open (_not_ File New at this time). Set the "Files of type" dropdown to "Document Templates (*.dot)". Use the "Look in" dropdown to navigate to the Templates folder, select SerRepCon.dot, and click OK. You're now able to edit the SerRepCon.dot template itself, not any document based on it. Put the cursor in the location where you want the sequence number to appear, and insert a bookmark named "Order". That same bookmark will automatically appear in each document you base on this template. Open the VBA editor. The Projects pane should include icons for Normal (because Normal.dot is always loaded), FineReader6SprintTools (which is an add-in from the FineReader program), Live Meeting Toolbar Customizations (another add-in), and SerRepCon. If you followed the directions exactly, there shouldn't be any others -- but if there are, ignore them. Select and expand the icon for "TemplateProject (SerRepCon)". It should contain a folder named "Microsoft Word Objects", in which there is a "ThisDocument" icon. Ignore those. Click the Insert Module command on the menu (in the VBA editor, not in Word's window). That will create a Modules folder under "TemplateProject (SerRepCon)", containing a "Module1" icon. To verify that you're in the right place, the code window should be empty and the title bar should say "Microsoft Visual Basic - SerRepCon - [Module1 (Code)]". Click in the code window and paste in the code of the AutoNew macro from our recent posts. Make sure it includes the lines to unprotect and reprotect the form. The two lines that mention System.PrivateProfileString should contain "C:\SerRepCon Sequence.txt" as the name of the file to contain the current sequence number. Close the VBA editor. Turn on form protection (click the lock icon on the Forms toolbar), save the template, and close it. Open the File New dialog (_not_ File Open -- now you're going to create a document based on the template). Select the SerRepCon template and click OK. You should see a document named "path00001.doc" that is a protected form with the sequence number 00001 at the place marked by the Order bookmark. Each time you go to File New and select the SerRepCon template as the basis for a new document, you should get another document and the sequence number should be greater by 1 than the one before. Now repeat all the previous steps for the template of another kind of form; the only difference should be that the lines that mention System.PrivateProfileString should contain the name of a different text file -- one related to that particular template. By the way, I don't think you really want the word "path" as part of the document's filename. The reason it's there now is that the original article on word.mvps.org shows it there -- but it was meant to represent the folder location (that is, the path from C:\ to the folder where you want the document to be stored), not the literal word "path". If you just want to store all the documents in the My Documents folder, you could change the Save statement to something like ActiveDocument.SaveAs FileName:="SerRepCon" & Format(Order, "0000#") so the actual name of a document based on this template would be something like SerRepCon00001.doc. Because the filename doesn't contain any information about the folder, Word automatically uses whatever folder you have set as the Documents location in the Tools Options File Locations dialog -- and by default that's the My Documents folder. -- 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. snulton wrote: I hope that I didn't upset you with my insessent questions, but I am going to repost this: I am probably beginning to sound really stupid. So let me see if I have it from the beginning. First I open a template (.dot) which automatically creates a document (.doc) that has a name "Document* (* = the number of the document opened and saved) then in that document I go to File New which opens a task pane that I then click on the Link for "On my Computer", I then receive a new Template (.dot) named "path0*****.dot, I then set my bookmark where I want the sequential numbers and then Go to Tools Macro Macros and am given a choice in the window that opens a blank space for Macro name, a bigger area that has AutoExec.MAIN, AutoExit.MAIN, and RunFineReader, with active buttons "Create", "Organizer", and "Close". Logic tells me that I would then "Create" AutoNew. This then opens Microsoft Visual Basic which has a panel that has a choice of "FineReader6SprintTools", "Normal", "Project (Document 1)" (with no modules), "TemplateProject (Live Meeting Toolbar Customizations)" and finally "TemplateProject (SerRepCon)" [the name of the original template], both the "Project (Document 1)" and the "TemplateProject (SerRepCon)" have "ThisDocument" when opening "Microsoft Word Objects". Which one do I use? The code window that opens caries the header of whichever main catagory is highlighted. This is the window that I put the AutoNew language. After this is done I would then click on the Save icon on the toolbar in Microsoft Visual Basic and shut window. then I would go to File SaveAs and name the document the same as the name used in the Macro before "sequence". Is this correct? Inf not Please correct within the messege. "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. |
#31
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
This is what I changed AutoNew to:
Sub AutoNew() Order = System.PrivateProfileString("C:\NRS Bid-proposal Sequence.Txt", "MacroSettings", "Order") If Order = "" Then Order = 1 Else Order = Order + 1 End If System.PrivateProfileString("C:\NRS Bid-proposal sequence.txt", "MacroSettings", "Order") = Order If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "04000#") ActiveDocument.Protect ActiveDocument.SaveAs FileName:="path" & Format(Order, "04000#") End Sub Then I lock it and save the template When I try to access a new document from that template the VBA editor opens with an error window that says "Compile error: Argument not optional" I then click on OK and Sub AutoNew() is high-lited in yellow and in ActiveDocument.Protect ".Protect is high-lited in blue "Jay Freedman" wrote: Did you include the code to unprotect the document and the code to protect the document? This was in my post of 10/182007: - ... insert new code before and after the InsertBefore line like this: If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "0000#") ActiveDocument.Protect ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") That will turn off the protection just long enough to insert the sequence number, and then turn the protection on again. -- 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. snulton wrote: Thank you Jay; I got it to work, however if the lock icon is clicked to protect the form when that template is accessed an Error messege: "Run-time error `4605` This method or property is not available because the object refers to a protected area of the document. appears. When clicking on "De-bug" The VBA opens the AutoNew window and highlites the second to last line before "End Sub" But without the document "protected" the numbering works. Thanks again "Jay Freedman" wrote: Hi Scott, I'm not upset; this is a complicated setup. But it does seem that you missed some fundamental principles, and I'm glad of the chance to start at the bottom and clear things up. Your paragraph "First I open a template ..." is not correct. Please wipe that blackboard clean, and we'll start from the beginning. I'll assume you have a template named SerRepCon.dot that contains the text of a contract. Within that text are some form fields. For each customer, you want to make a document based on the template, in which the form fields will be filled in differently. Some place in the document you want to put a sequence number that will be different for each document, and that number will also become part of the document's file name. Right so far? I'll also assume that at this point the SerRepCon.dot template doesn't contain any macros, and that the template file is stored in your Templates folder (something like C:\Documents and Settings\snulton\Application Data\Microsoft\Templates). Start the Word program. Click File Open (_not_ File New at this time). Set the "Files of type" dropdown to "Document Templates (*.dot)". Use the "Look in" dropdown to navigate to the Templates folder, select SerRepCon.dot, and click OK. You're now able to edit the SerRepCon.dot template itself, not any document based on it. Put the cursor in the location where you want the sequence number to appear, and insert a bookmark named "Order". That same bookmark will automatically appear in each document you base on this template. Open the VBA editor. The Projects pane should include icons for Normal (because Normal.dot is always loaded), FineReader6SprintTools (which is an add-in from the FineReader program), Live Meeting Toolbar Customizations (another add-in), and SerRepCon. If you followed the directions exactly, there shouldn't be any others -- but if there are, ignore them. Select and expand the icon for "TemplateProject (SerRepCon)". It should contain a folder named "Microsoft Word Objects", in which there is a "ThisDocument" icon. Ignore those. Click the Insert Module command on the menu (in the VBA editor, not in Word's window). That will create a Modules folder under "TemplateProject (SerRepCon)", containing a "Module1" icon. To verify that you're in the right place, the code window should be empty and the title bar should say "Microsoft Visual Basic - SerRepCon - [Module1 (Code)]". Click in the code window and paste in the code of the AutoNew macro from our recent posts. Make sure it includes the lines to unprotect and reprotect the form. The two lines that mention System.PrivateProfileString should contain "C:\SerRepCon Sequence.txt" as the name of the file to contain the current sequence number. Close the VBA editor. Turn on form protection (click the lock icon on the Forms toolbar), save the template, and close it. Open the File New dialog (_not_ File Open -- now you're going to create a document based on the template). Select the SerRepCon template and click OK. You should see a document named "path00001.doc" that is a protected form with the sequence number 00001 at the place marked by the Order bookmark. Each time you go to File New and select the SerRepCon template as the basis for a new document, you should get another document and the sequence number should be greater by 1 than the one before. Now repeat all the previous steps for the template of another kind of form; the only difference should be that the lines that mention System.PrivateProfileString should contain the name of a different text file -- one related to that particular template. By the way, I don't think you really want the word "path" as part of the document's filename. The reason it's there now is that the original article on word.mvps.org shows it there -- but it was meant to represent the folder location (that is, the path from C:\ to the folder where you want the document to be stored), not the literal word "path". If you just want to store all the documents in the My Documents folder, you could change the Save statement to something like ActiveDocument.SaveAs FileName:="SerRepCon" & Format(Order, "0000#") so the actual name of a document based on this template would be something like SerRepCon00001.doc. Because the filename doesn't contain any information about the folder, Word automatically uses whatever folder you have set as the Documents location in the Tools Options File Locations dialog -- and by default that's the My Documents folder. -- 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. snulton wrote: I hope that I didn't upset you with my insessent questions, but I am going to repost this: I am probably beginning to sound really stupid. So let me see if I have it from the beginning. First I open a template (.dot) which automatically creates a document (.doc) that has a name "Document* (* = the number of the document opened and saved) then in that document I go to File New which opens a task pane that I then click on the Link for "On my Computer", I then receive a new Template (.dot) named "path0*****.dot, I then set my bookmark where I want the sequential numbers and then Go to Tools Macro Macros and am given a choice in the window that opens a blank space for Macro name, a bigger area that has AutoExec.MAIN, AutoExit.MAIN, and RunFineReader, with active buttons "Create", "Organizer", and "Close". Logic tells me that I would then "Create" AutoNew. This then opens Microsoft Visual Basic which has a panel that has a choice of "FineReader6SprintTools", "Normal", "Project (Document 1)" (with no modules), "TemplateProject (Live Meeting Toolbar Customizations)" and finally "TemplateProject (SerRepCon)" [the name of the original template], both the "Project (Document 1)" and the "TemplateProject (SerRepCon)" have "ThisDocument" when opening "Microsoft Word Objects". Which one do I use? The code window that opens caries the header of whichever main catagory is highlighted. This is the window that I put the AutoNew language. After this is done I would then click on the Save icon on the toolbar in Microsoft Visual Basic and shut window. then I would go to File SaveAs and name the document the same as the name used in the Macro before "sequence". Is this correct? Inf not Please correct within the messege. "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. |
#32
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
My apologies... that one is my fault. The line should be
ActiveDocument.Protect wdAllowOnlyFormFields (There are several possible kinds of protection, so the Protect command insists on being told which kind to use.) On Thu, 25 Oct 2007 12:50:04 -0700, snulton wrote: This is what I changed AutoNew to: Sub AutoNew() Order = System.PrivateProfileString("C:\NRS Bid-proposal Sequence.Txt", "MacroSettings", "Order") If Order = "" Then Order = 1 Else Order = Order + 1 End If System.PrivateProfileString("C:\NRS Bid-proposal sequence.txt", "MacroSettings", "Order") = Order If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBef ore Format(Order, "04000#") ActiveDocument.Protect ActiveDocument.SaveAs FileName:="path" & Format(Order, "04000#") End Sub Then I lock it and save the template When I try to access a new document from that template the VBA editor opens with an error window that says "Compile error: Argument not optional" I then click on OK and Sub AutoNew() is high-lited in yellow and in ActiveDocument.Protect ".Protect is high-lited in blue "Jay Freedman" wrote: Did you include the code to unprotect the document and the code to protect the document? This was in my post of 10/182007: - ... insert new code before and after the InsertBefore line like this: If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "0000#") ActiveDocument.Protect ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") That will turn off the protection just long enough to insert the sequence number, and then turn the protection on again. -- 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. snulton wrote: Thank you Jay; I got it to work, however if the lock icon is clicked to protect the form when that template is accessed an Error messege: "Run-time error `4605` This method or property is not available because the object refers to a protected area of the document. appears. When clicking on "De-bug" The VBA opens the AutoNew window and highlites the second to last line before "End Sub" But without the document "protected" the numbering works. Thanks again "Jay Freedman" wrote: Hi Scott, I'm not upset; this is a complicated setup. But it does seem that you missed some fundamental principles, and I'm glad of the chance to start at the bottom and clear things up. Your paragraph "First I open a template ..." is not correct. Please wipe that blackboard clean, and we'll start from the beginning. I'll assume you have a template named SerRepCon.dot that contains the text of a contract. Within that text are some form fields. For each customer, you want to make a document based on the template, in which the form fields will be filled in differently. Some place in the document you want to put a sequence number that will be different for each document, and that number will also become part of the document's file name. Right so far? I'll also assume that at this point the SerRepCon.dot template doesn't contain any macros, and that the template file is stored in your Templates folder (something like C:\Documents and Settings\snulton\Application Data\Microsoft\Templates). Start the Word program. Click File Open (_not_ File New at this time). Set the "Files of type" dropdown to "Document Templates (*.dot)". Use the "Look in" dropdown to navigate to the Templates folder, select SerRepCon.dot, and click OK. You're now able to edit the SerRepCon.dot template itself, not any document based on it. Put the cursor in the location where you want the sequence number to appear, and insert a bookmark named "Order". That same bookmark will automatically appear in each document you base on this template. Open the VBA editor. The Projects pane should include icons for Normal (because Normal.dot is always loaded), FineReader6SprintTools (which is an add-in from the FineReader program), Live Meeting Toolbar Customizations (another add-in), and SerRepCon. If you followed the directions exactly, there shouldn't be any others -- but if there are, ignore them. Select and expand the icon for "TemplateProject (SerRepCon)". It should contain a folder named "Microsoft Word Objects", in which there is a "ThisDocument" icon. Ignore those. Click the Insert Module command on the menu (in the VBA editor, not in Word's window). That will create a Modules folder under "TemplateProject (SerRepCon)", containing a "Module1" icon. To verify that you're in the right place, the code window should be empty and the title bar should say "Microsoft Visual Basic - SerRepCon - [Module1 (Code)]". Click in the code window and paste in the code of the AutoNew macro from our recent posts. Make sure it includes the lines to unprotect and reprotect the form. The two lines that mention System.PrivateProfileString should contain "C:\SerRepCon Sequence.txt" as the name of the file to contain the current sequence number. Close the VBA editor. Turn on form protection (click the lock icon on the Forms toolbar), save the template, and close it. Open the File New dialog (_not_ File Open -- now you're going to create a document based on the template). Select the SerRepCon template and click OK. You should see a document named "path00001.doc" that is a protected form with the sequence number 00001 at the place marked by the Order bookmark. Each time you go to File New and select the SerRepCon template as the basis for a new document, you should get another document and the sequence number should be greater by 1 than the one before. Now repeat all the previous steps for the template of another kind of form; the only difference should be that the lines that mention System.PrivateProfileString should contain the name of a different text file -- one related to that particular template. By the way, I don't think you really want the word "path" as part of the document's filename. The reason it's there now is that the original article on word.mvps.org shows it there -- but it was meant to represent the folder location (that is, the path from C:\ to the folder where you want the document to be stored), not the literal word "path". If you just want to store all the documents in the My Documents folder, you could change the Save statement to something like ActiveDocument.SaveAs FileName:="SerRepCon" & Format(Order, "0000#") so the actual name of a document based on this template would be something like SerRepCon00001.doc. Because the filename doesn't contain any information about the folder, Word automatically uses whatever folder you have set as the Documents location in the Tools Options File Locations dialog -- and by default that's the My Documents folder. -- 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. snulton wrote: I hope that I didn't upset you with my insessent questions, but I am going to repost this: I am probably beginning to sound really stupid. So let me see if I have it from the beginning. First I open a template (.dot) which automatically creates a document (.doc) that has a name "Document* (* = the number of the document opened and saved) then in that document I go to File New which opens a task pane that I then click on the Link for "On my Computer", I then receive a new Template (.dot) named "path0*****.dot, I then set my bookmark where I want the sequential numbers and then Go to Tools Macro Macros and am given a choice in the window that opens a blank space for Macro name, a bigger area that has AutoExec.MAIN, AutoExit.MAIN, and RunFineReader, with active buttons "Create", "Organizer", and "Close". Logic tells me that I would then "Create" AutoNew. This then opens Microsoft Visual Basic which has a panel that has a choice of "FineReader6SprintTools", "Normal", "Project (Document 1)" (with no modules), "TemplateProject (Live Meeting Toolbar Customizations)" and finally "TemplateProject (SerRepCon)" [the name of the original template], both the "Project (Document 1)" and the "TemplateProject (SerRepCon)" have "ThisDocument" when opening "Microsoft Word Objects". Which one do I use? The code window that opens caries the header of whichever main catagory is highlighted. This is the window that I put the AutoNew language. After this is done I would then click on the Save icon on the toolbar in Microsoft Visual Basic and shut window. then I would go to File SaveAs and name the document the same as the name used in the Macro before "sequence". Is this correct? Inf not Please correct within the messege. "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. |
#33
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
Jay,
When I copy the templates (that work now,YEA :-) ) to my server so other people on the network can use them, I get a MVB window that states "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." This also happens when I attempt to access the templates from other stations on the network, and when I create shortcuts to my template folder. If I put shortcuts to my template folder in the folder on the server I can open the templates just fine, but only off my own machine. Is this a complicated work arround? "Jay Freedman" wrote: My apologies... that one is my fault. The line should be ActiveDocument.Protect wdAllowOnlyFormFields (There are several possible kinds of protection, so the Protect command insists on being told which kind to use.) On Thu, 25 Oct 2007 12:50:04 -0700, snulton wrote: This is what I changed AutoNew to: Sub AutoNew() Order = System.PrivateProfileString("C:\NRS Bid-proposal Sequence.Txt", "MacroSettings", "Order") If Order = "" Then Order = 1 Else Order = Order + 1 End If System.PrivateProfileString("C:\NRS Bid-proposal sequence.txt", "MacroSettings", "Order") = Order If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBef ore Format(Order, "04000#") ActiveDocument.Protect ActiveDocument.SaveAs FileName:="path" & Format(Order, "04000#") End Sub Then I lock it and save the template When I try to access a new document from that template the VBA editor opens with an error window that says "Compile error: Argument not optional" I then click on OK and Sub AutoNew() is high-lited in yellow and in ActiveDocument.Protect ".Protect is high-lited in blue "Jay Freedman" wrote: Did you include the code to unprotect the document and the code to protect the document? This was in my post of 10/182007: - ... insert new code before and after the InsertBefore line like this: If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "0000#") ActiveDocument.Protect ActiveDocument.SaveAs FileName:="path" & Format(Order, "0000#") That will turn off the protection just long enough to insert the sequence number, and then turn the protection on again. -- 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. snulton wrote: Thank you Jay; I got it to work, however if the lock icon is clicked to protect the form when that template is accessed an Error messege: "Run-time error `4605` This method or property is not available because the object refers to a protected area of the document. appears. When clicking on "De-bug" The VBA opens the AutoNew window and highlites the second to last line before "End Sub" But without the document "protected" the numbering works. Thanks again "Jay Freedman" wrote: Hi Scott, I'm not upset; this is a complicated setup. But it does seem that you missed some fundamental principles, and I'm glad of the chance to start at the bottom and clear things up. Your paragraph "First I open a template ..." is not correct. Please wipe that blackboard clean, and we'll start from the beginning. I'll assume you have a template named SerRepCon.dot that contains the text of a contract. Within that text are some form fields. For each customer, you want to make a document based on the template, in which the form fields will be filled in differently. Some place in the document you want to put a sequence number that will be different for each document, and that number will also become part of the document's file name. Right so far? I'll also assume that at this point the SerRepCon.dot template doesn't contain any macros, and that the template file is stored in your Templates folder (something like C:\Documents and Settings\snulton\Application Data\Microsoft\Templates). Start the Word program. Click File Open (_not_ File New at this time). Set the "Files of type" dropdown to "Document Templates (*.dot)". Use the "Look in" dropdown to navigate to the Templates folder, select SerRepCon.dot, and click OK. You're now able to edit the SerRepCon.dot template itself, not any document based on it. Put the cursor in the location where you want the sequence number to appear, and insert a bookmark named "Order". That same bookmark will automatically appear in each document you base on this template. Open the VBA editor. The Projects pane should include icons for Normal (because Normal.dot is always loaded), FineReader6SprintTools (which is an add-in from the FineReader program), Live Meeting Toolbar Customizations (another add-in), and SerRepCon. If you followed the directions exactly, there shouldn't be any others -- but if there are, ignore them. Select and expand the icon for "TemplateProject (SerRepCon)". It should contain a folder named "Microsoft Word Objects", in which there is a "ThisDocument" icon. Ignore those. Click the Insert Module command on the menu (in the VBA editor, not in Word's window). That will create a Modules folder under "TemplateProject (SerRepCon)", containing a "Module1" icon. To verify that you're in the right place, the code window should be empty and the title bar should say "Microsoft Visual Basic - SerRepCon - [Module1 (Code)]". Click in the code window and paste in the code of the AutoNew macro from our recent posts. Make sure it includes the lines to unprotect and reprotect the form. The two lines that mention System.PrivateProfileString should contain "C:\SerRepCon Sequence.txt" as the name of the file to contain the current sequence number. Close the VBA editor. Turn on form protection (click the lock icon on the Forms toolbar), save the template, and close it. Open the File New dialog (_not_ File Open -- now you're going to create a document based on the template). Select the SerRepCon template and click OK. You should see a document named "path00001.doc" that is a protected form with the sequence number 00001 at the place marked by the Order bookmark. Each time you go to File New and select the SerRepCon template as the basis for a new document, you should get another document and the sequence number should be greater by 1 than the one before. Now repeat all the previous steps for the template of another kind of form; the only difference should be that the lines that mention System.PrivateProfileString should contain the name of a different text file -- one related to that particular template. By the way, I don't think you really want the word "path" as part of the document's filename. The reason it's there now is that the original article on word.mvps.org shows it there -- but it was meant to represent the folder location (that is, the path from C:\ to the folder where you want the document to be stored), not the literal word "path". If you just want to store all the documents in the My Documents folder, you could change the Save statement to something like ActiveDocument.SaveAs FileName:="SerRepCon" & Format(Order, "0000#") so the actual name of a document based on this template would be something like SerRepCon00001.doc. Because the filename doesn't contain any information about the folder, Word automatically uses whatever folder you have set as the Documents location in the Tools Options File Locations dialog -- and by default that's the My Documents folder. -- 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. snulton wrote: I hope that I didn't upset you with my insessent questions, but I am going to repost this: I am probably beginning to sound really stupid. So let me see if I have it from the beginning. First I open a template (.dot) which automatically creates a document (.doc) that has a name "Document* (* = the number of the document opened and saved) then in that document I go to File New which opens a task pane that I then click on the Link for "On my Computer", I then receive a new Template (.dot) named "path0*****.dot, I then set my bookmark where I want the sequential numbers and then Go to Tools Macro Macros and am given a choice in the window that opens a blank space for Macro name, a bigger area that has AutoExec.MAIN, AutoExit.MAIN, and RunFineReader, with active buttons "Create", "Organizer", and "Close". Logic tells me that I would then "Create" AutoNew. This then opens Microsoft Visual Basic which has a panel that has a choice of "FineReader6SprintTools", "Normal", "Project (Document 1)" (with no modules), "TemplateProject (Live Meeting Toolbar Customizations)" and finally "TemplateProject (SerRepCon)" [the name of the original template], both the "Project (Document 1)" and the "TemplateProject (SerRepCon)" have "ThisDocument" when opening "Microsoft Word Objects". Which one do I use? The code window that opens caries the header of whichever main catagory is highlighted. This is the window that I put the AutoNew language. After this is done I would then click on the Save icon on the toolbar in Microsoft Visual Basic and shut window. then I would go to File SaveAs and name the document the same as the name used in the Macro before "sequence". Is this correct? Inf not Please correct within the messege. "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. |
#34
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
I don't know quite what you can do -- I don't have access to a server to try
fiddling with it. The message is the standard one you get when Word finds macros either in any document (*.doc) or in a template from an "untrusted" location while the macro security level is set to High. For Word 2003 and earlier, only the local Templates and Startup folders are trusted; Word 2007 allows (theoretically, anyway) choosing other locations to be trusted. Go to Tools Macro Security and see what level is set -- each computer will have its own setting, and there's no way to change them from outside. If they're set to High, try changing them to Medium, which should give you a choice of disabling or enabling the macros (of course, since you know this isn't a virus, you should choose Enable). The Low setting is not recommended. Another thing that might work -- no promises -- is to go to Tools Options File Locations and set the Workgroup location to point to the folder on the server. It's worth a try. The only thing I know that's guaranteed to work is digitally signing the macros with a security certificate. Unless you have a corporate security server that can issue certificates, though, it'll cost several hundred dollars to get one from Verisign or Thawte. -- 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. snulton wrote: Jay, When I copy the templates (that work now,YEA :-) ) to my server so other people on the network can use them, I get a MVB window that states "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." This also happens when I attempt to access the templates from other stations on the network, and when I create shortcuts to my template folder. If I put shortcuts to my template folder in the folder on the server I can open the templates just fine, but only off my own machine. Is this a complicated work arround? |
#35
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
"Jay Freedman" wrote: I don't know quite what you can do -- I don't have access to a server to try fiddling with it. The message is the standard one you get when Word finds macros either in any document (*.doc) or in a template from an "untrusted" location while the macro security level is set to High. For Word 2003 and earlier, only the local Templates and Startup folders are trusted; Word 2007 allows (theoretically, anyway) choosing other locations to be trusted. Go to Tools Macro Security and see what level is set -- each computer will have its own setting, and there's no way to change them from outside. If they're set to High, try changing them to Medium, which should give you a choice of disabling or enabling the macros (of course, since you know this isn't a virus, you should choose Enable). The Low setting is not recommended. Another thing that might work -- no promises -- is to go to Tools Options File Locations and set the Workgroup location to point to the folder on the server. It's worth a try. The only thing I know that's guaranteed to work is digitally signing the macros with a security certificate. Unless you have a corporate security server that can issue certificates, though, it'll cost several hundred dollars to get one from Verisign or Thawte. -- 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. snulton wrote: Jay, When I copy the templates (that work now,YEA :-) ) to my server so other people on the network can use them, I get a MVB window that states "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." This also happens when I attempt to access the templates from other stations on the network, and when I create shortcuts to my template folder. If I put shortcuts to my template folder in the folder on the server I can open the templates just fine, but only off my own machine. Is this a complicated work arround? |
#36
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
I was able to gain access to the templates by changing the level to medium.
This brought up another small challenge; the numbers are only sequential per machine, i.e. if I am on one machine the number that opens might be 030028 but opening from a machine that has not accessed that template before will get 030001. Is this something that can be made to work so that each time the template is opened from any terminal the number will be truly sequential or arer we limited to using only one machine to write all contracts? "Jay Freedman" wrote: I don't know quite what you can do -- I don't have access to a server to try fiddling with it. The message is the standard one you get when Word finds macros either in any document (*.doc) or in a template from an "untrusted" location while the macro security level is set to High. For Word 2003 and earlier, only the local Templates and Startup folders are trusted; Word 2007 allows (theoretically, anyway) choosing other locations to be trusted. Go to Tools Macro Security and see what level is set -- each computer will have its own setting, and there's no way to change them from outside. If they're set to High, try changing them to Medium, which should give you a choice of disabling or enabling the macros (of course, since you know this isn't a virus, you should choose Enable). The Low setting is not recommended. Another thing that might work -- no promises -- is to go to Tools Options File Locations and set the Workgroup location to point to the folder on the server. It's worth a try. The only thing I know that's guaranteed to work is digitally signing the macros with a security certificate. Unless you have a corporate security server that can issue certificates, though, it'll cost several hundred dollars to get one from Verisign or Thawte. -- 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. snulton wrote: Jay, When I copy the templates (that work now,YEA :-) ) to my server so other people on the network can use them, I get a MVB window that states "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." This also happens when I attempt to access the templates from other stations on the network, and when I create shortcuts to my template folder. If I put shortcuts to my template folder in the folder on the server I can open the templates just fine, but only off my own machine. Is this a complicated work arround? |
#37
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
The reason the numbers are per-machine is that the macro is reading data
from, and writing data to, a local file on whatever machine the macro is currently running on. Change the macro (in the two lines that mention System.PrivateProfileString) to read and write a file in a shared folder, and you should get everybody working with the same sequence -- although there's a gotcha. Working with previous examples from this thread, you should replace Order = System.PrivateProfileString("C:\NRS RemContract Sequence.Txt","MacroSettings","Order) and System.PrivateProfileString("C:\NRS RemContract Sequence.Txt","MacroSettings","Order) = Order with the lines Order = System.PrivateProfileString("\\servername\folderna me\NRS RemContract Sequence.Txt","MacroSettings","Order) and System.PrivateProfileString("\\servername\folderna me\NRS RemContract Sequence.Txt","MacroSettings","Order) = Order Of course, I mean that "servername" should be replaced with the actual name of the server, and "foldername" should be replaced with the name of the shared folder. (If everybody has the same drive letter permanently mapped to the shared folder, you can use that instead of the servername\foldername form; but that's harder to maintain.) The gotcha is that there's no good way to make sure there are no collisions -- that a macro for user A might try to read or write the file at the same moment that user B's macro has the file open, which would cause an error message. It should be very rare, though, because each access to the file is very fast. snulton wrote: I was able to gain access to the templates by changing the level to medium. This brought up another small challenge; the numbers are only sequential per machine, i.e. if I am on one machine the number that opens might be 030028 but opening from a machine that has not accessed that template before will get 030001. Is this something that can be made to work so that each time the template is opened from any terminal the number will be truly sequential or arer we limited to using only one machine to write all contracts? "Jay Freedman" wrote: I don't know quite what you can do -- I don't have access to a server to try fiddling with it. The message is the standard one you get when Word finds macros either in any document (*.doc) or in a template from an "untrusted" location while the macro security level is set to High. For Word 2003 and earlier, only the local Templates and Startup folders are trusted; Word 2007 allows (theoretically, anyway) choosing other locations to be trusted. Go to Tools Macro Security and see what level is set -- each computer will have its own setting, and there's no way to change them from outside. If they're set to High, try changing them to Medium, which should give you a choice of disabling or enabling the macros (of course, since you know this isn't a virus, you should choose Enable). The Low setting is not recommended. Another thing that might work -- no promises -- is to go to Tools Options File Locations and set the Workgroup location to point to the folder on the server. It's worth a try. The only thing I know that's guaranteed to work is digitally signing the macros with a security certificate. Unless you have a corporate security server that can issue certificates, though, it'll cost several hundred dollars to get one from Verisign or Thawte. -- 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. snulton wrote: Jay, When I copy the templates (that work now,YEA :-) ) to my server so other people on the network can use them, I get a MVB window that states "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." This also happens when I attempt to access the templates from other stations on the network, and when I create shortcuts to my template folder. If I put shortcuts to my template folder in the folder on the server I can open the templates just fine, but only off my own machine. Is this a complicated work arround? |
#38
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
OK, I changed the AutoNew to read like this:
Sub AutoNew() Order = System.PrivateProfileString("\\Server\data\Templat es\NRS RemContract Sequence.Txt","MacroSettings","Order) If Order = "" Then Order = 1 Else Order = Order + 1 End If System.PrivateProfileString("\\Server\data\Templat es\NRS RemContract Sequence.Txt","MacroSettings","Order) = Order If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "04000#") ActiveDocument.Protect wdAllowOnlyFormFields ActiveDocument.SaveAs FileName:="path" & Format(Order, "04000#") End Sub And so on for NRS Bid-proposal, and NRS Service-Repair Contract, I get Compile error: Syntax error (with the very first line highlited); and Compile error: Expected:List seperator or ) What hav I done wrong now? The pathway is a cut and paste from accessing the templates from any of the computers. "Jay Freedman" wrote: The reason the numbers are per-machine is that the macro is reading data from, and writing data to, a local file on whatever machine the macro is currently running on. Change the macro (in the two lines that mention System.PrivateProfileString) to read and write a file in a shared folder, and you should get everybody working with the same sequence -- although there's a gotcha. Working with previous examples from this thread, you should replace Order = System.PrivateProfileString("C:\NRS RemContract Sequence.Txt","MacroSettings","Order) and System.PrivateProfileString("C:\NRS RemContract Sequence.Txt","MacroSettings","Order) = Order with the lines Order = System.PrivateProfileString("\\servername\folderna me\NRS RemContract Sequence.Txt","MacroSettings","Order) and System.PrivateProfileString("\\servername\folderna me\NRS RemContract Sequence.Txt","MacroSettings","Order) = Order Of course, I mean that "servername" should be replaced with the actual name of the server, and "foldername" should be replaced with the name of the shared folder. (If everybody has the same drive letter permanently mapped to the shared folder, you can use that instead of the servername\foldername form; but that's harder to maintain.) The gotcha is that there's no good way to make sure there are no collisions -- that a macro for user A might try to read or write the file at the same moment that user B's macro has the file open, which would cause an error message. It should be very rare, though, because each access to the file is very fast. snulton wrote: I was able to gain access to the templates by changing the level to medium. This brought up another small challenge; the numbers are only sequential per machine, i.e. if I am on one machine the number that opens might be 030028 but opening from a machine that has not accessed that template before will get 030001. Is this something that can be made to work so that each time the template is opened from any terminal the number will be truly sequential or arer we limited to using only one machine to write all contracts? "Jay Freedman" wrote: I don't know quite what you can do -- I don't have access to a server to try fiddling with it. The message is the standard one you get when Word finds macros either in any document (*.doc) or in a template from an "untrusted" location while the macro security level is set to High. For Word 2003 and earlier, only the local Templates and Startup folders are trusted; Word 2007 allows (theoretically, anyway) choosing other locations to be trusted. Go to Tools Macro Security and see what level is set -- each computer will have its own setting, and there's no way to change them from outside. If they're set to High, try changing them to Medium, which should give you a choice of disabling or enabling the macros (of course, since you know this isn't a virus, you should choose Enable). The Low setting is not recommended. Another thing that might work -- no promises -- is to go to Tools Options File Locations and set the Workgroup location to point to the folder on the server. It's worth a try. The only thing I know that's guaranteed to work is digitally signing the macros with a security certificate. Unless you have a corporate security server that can issue certificates, though, it'll cost several hundred dollars to get one from Verisign or Thawte. -- 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. snulton wrote: Jay, When I copy the templates (that work now,YEA :-) ) to my server so other people on the network can use them, I get a MVB window that states "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." This also happens when I attempt to access the templates from other stations on the network, and when I create shortcuts to my template folder. If I put shortcuts to my template folder in the folder on the server I can open the templates just fine, but only off my own machine. Is this a complicated work arround? |
#39
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
What's wrong is something simple but very easy to overlook: In each of the
PrivateProfileString expressions, you're missing a double-quote character between Order and the closing parenthesis -- that is, you have "MacroSettings","Order) instead of "MacroSettings","Order") That applies _only_ to the occurrence immediately before the closing parenthesis, not to the other one in the line. By the way, I was able to get a temporary share on a server and tried this, and it does work when you get the syntax correct. :-) snulton wrote: OK, I changed the AutoNew to read like this: Sub AutoNew() Order = System.PrivateProfileString("\\Server\data\Templat es\NRS RemContract Sequence.Txt","MacroSettings","Order) If Order = "" Then Order = 1 Else Order = Order + 1 End If System.PrivateProfileString("\\Server\data\Templat es\NRS RemContract Sequence.Txt","MacroSettings","Order) = Order If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "04000#") ActiveDocument.Protect wdAllowOnlyFormFields ActiveDocument.SaveAs FileName:="path" & Format(Order, "04000#") End Sub And so on for NRS Bid-proposal, and NRS Service-Repair Contract, I get Compile error: Syntax error (with the very first line highlited); and Compile error: Expected:List seperator or ) What hav I done wrong now? The pathway is a cut and paste from accessing the templates from any of the computers. "Jay Freedman" wrote: The reason the numbers are per-machine is that the macro is reading data from, and writing data to, a local file on whatever machine the macro is currently running on. Change the macro (in the two lines that mention System.PrivateProfileString) to read and write a file in a shared folder, and you should get everybody working with the same sequence -- although there's a gotcha. Working with previous examples from this thread, you should replace Order = System.PrivateProfileString("C:\NRS RemContract Sequence.Txt","MacroSettings","Order) and System.PrivateProfileString("C:\NRS RemContract Sequence.Txt","MacroSettings","Order) = Order with the lines Order = System.PrivateProfileString("\\servername\folderna me\NRS RemContract Sequence.Txt","MacroSettings","Order) and System.PrivateProfileString("\\servername\folderna me\NRS RemContract Sequence.Txt","MacroSettings","Order) = Order Of course, I mean that "servername" should be replaced with the actual name of the server, and "foldername" should be replaced with the name of the shared folder. (If everybody has the same drive letter permanently mapped to the shared folder, you can use that instead of the servername\foldername form; but that's harder to maintain.) The gotcha is that there's no good way to make sure there are no collisions -- that a macro for user A might try to read or write the file at the same moment that user B's macro has the file open, which would cause an error message. It should be very rare, though, because each access to the file is very fast. snulton wrote: I was able to gain access to the templates by changing the level to medium. This brought up another small challenge; the numbers are only sequential per machine, i.e. if I am on one machine the number that opens might be 030028 but opening from a machine that has not accessed that template before will get 030001. Is this something that can be made to work so that each time the template is opened from any terminal the number will be truly sequential or arer we limited to using only one machine to write all contracts? "Jay Freedman" wrote: I don't know quite what you can do -- I don't have access to a server to try fiddling with it. The message is the standard one you get when Word finds macros either in any document (*.doc) or in a template from an "untrusted" location while the macro security level is set to High. For Word 2003 and earlier, only the local Templates and Startup folders are trusted; Word 2007 allows (theoretically, anyway) choosing other locations to be trusted. Go to Tools Macro Security and see what level is set -- each computer will have its own setting, and there's no way to change them from outside. If they're set to High, try changing them to Medium, which should give you a choice of disabling or enabling the macros (of course, since you know this isn't a virus, you should choose Enable). The Low setting is not recommended. Another thing that might work -- no promises -- is to go to Tools Options File Locations and set the Workgroup location to point to the folder on the server. It's worth a try. The only thing I know that's guaranteed to work is digitally signing the macros with a security certificate. Unless you have a corporate security server that can issue certificates, though, it'll cost several hundred dollars to get one from Verisign or Thawte. -- 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. snulton wrote: Jay, When I copy the templates (that work now,YEA :-) ) to my server so other people on the network can use them, I get a MVB window that states "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." This also happens when I attempt to access the templates from other stations on the network, and when I create shortcuts to my template folder. If I put shortcuts to my template folder in the folder on the server I can open the templates just fine, but only off my own machine. Is this a complicated work arround? |
#40
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How do I set up automatically suceeding numbers in Word?
OK! I have it set up like this:
Sub AutoNew() Order = System.PrivateProfileString("\\Server\data\Templat es\NRS RemContract Sequence.Txt","MacroSettings","Order€¯ If Order = "" Then Order = 1 Else Order = Order + 1 End If System.PrivateProfileString("\\Server\data\Templat es\NRS RemContract Sequence.Txt","MacroSettings","Order€¯ = Order If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "04000#") ActiveDocument.Protect wdAllowOnlyFormFields ActiveDocument.SaveAs FileName:="path" & Format(Order, "04000#") End Sub and I still get a different set of numbers from different computers. I have been working on my own terminal so now the numbers on NRS RemContract when opened on my computer will have (now) 030032. when opened on my designers computer I will get 030002, not 030033 "Jay Freedman" wrote: What's wrong is something simple but very easy to overlook: In each of the PrivateProfileString expressions, you're missing a double-quote character between Order and the closing parenthesis -- that is, you have "MacroSettings","Order) instead of "MacroSettings","Order") That applies _only_ to the occurrence immediately before the closing parenthesis, not to the other one in the line. By the way, I was able to get a temporary share on a server and tried this, and it does work when you get the syntax correct. :-) snulton wrote: OK, I changed the AutoNew to read like this: Sub AutoNew() Order = System.PrivateProfileString("\\Server\data\Templat es\NRS RemContract Sequence.Txt","MacroSettings","Order) If Order = "" Then Order = 1 Else Order = Order + 1 End If System.PrivateProfileString("\\Server\data\Templat es\NRS RemContract Sequence.Txt","MacroSettings","Order) = Order If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "04000#") ActiveDocument.Protect wdAllowOnlyFormFields ActiveDocument.SaveAs FileName:="path" & Format(Order, "04000#") End Sub And so on for NRS Bid-proposal, and NRS Service-Repair Contract, I get Compile error: Syntax error (with the very first line highlited); and Compile error: Expected:List seperator or ) What hav I done wrong now? The pathway is a cut and paste from accessing the templates from any of the computers. "Jay Freedman" wrote: The reason the numbers are per-machine is that the macro is reading data from, and writing data to, a local file on whatever machine the macro is currently running on. Change the macro (in the two lines that mention System.PrivateProfileString) to read and write a file in a shared folder, and you should get everybody working with the same sequence -- although there's a gotcha. Working with previous examples from this thread, you should replace Order = System.PrivateProfileString("C:\NRS RemContract Sequence.Txt","MacroSettings","Order) and System.PrivateProfileString("C:\NRS RemContract Sequence.Txt","MacroSettings","Order) = Order with the lines Order = System.PrivateProfileString("\\servername\folderna me\NRS RemContract Sequence.Txt","MacroSettings","Order) and System.PrivateProfileString("\\servername\folderna me\NRS RemContract Sequence.Txt","MacroSettings","Order) = Order Of course, I mean that "servername" should be replaced with the actual name of the server, and "foldername" should be replaced with the name of the shared folder. (If everybody has the same drive letter permanently mapped to the shared folder, you can use that instead of the servername\foldername form; but that's harder to maintain.) The gotcha is that there's no good way to make sure there are no collisions -- that a macro for user A might try to read or write the file at the same moment that user B's macro has the file open, which would cause an error message. It should be very rare, though, because each access to the file is very fast. snulton wrote: I was able to gain access to the templates by changing the level to medium. This brought up another small challenge; the numbers are only sequential per machine, i.e. if I am on one machine the number that opens might be 030028 but opening from a machine that has not accessed that template before will get 030001. Is this something that can be made to work so that each time the template is opened from any terminal the number will be truly sequential or arer we limited to using only one machine to write all contracts? "Jay Freedman" wrote: I don't know quite what you can do -- I don't have access to a server to try fiddling with it. The message is the standard one you get when Word finds macros either in any document (*.doc) or in a template from an "untrusted" location while the macro security level is set to High. For Word 2003 and earlier, only the local Templates and Startup folders are trusted; Word 2007 allows (theoretically, anyway) choosing other locations to be trusted. Go to Tools Macro Security and see what level is set -- each computer will have its own setting, and there's no way to change them from outside. If they're set to High, try changing them to Medium, which should give you a choice of disabling or enabling the macros (of course, since you know this isn't a virus, you should choose Enable). The Low setting is not recommended. Another thing that might work -- no promises -- is to go to Tools Options File Locations and set the Workgroup location to point to the folder on the server. It's worth a try. The only thing I know that's guaranteed to work is digitally signing the macros with a security certificate. Unless you have a corporate security server that can issue certificates, though, it'll cost several hundred dollars to get one from Verisign or Thawte. -- 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. snulton wrote: Jay, When I copy the templates (that work now,YEA :-) ) to my server so other people on the network can use them, I get a MVB window that states "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." This also happens when I attempt to access the templates from other stations on the network, and when I create shortcuts to my template folder. If I put shortcuts to my template folder in the folder on the server I can open the templates just fine, but only off my own machine. Is this a complicated work arround? |
Reply |
|
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
In Word, how can I automatically insert a comma between numbers? | Microsoft Word Help | |||
how do i automatically phone numbers on a word document? | Microsoft Word Help | |||
How to add a counter in Word? The numbers automatically go up | Microsoft Word Help | |||
Can I automatically add superscript sentence numbers in Word? | Microsoft Word Help | |||
How do I get Word to automatically add page numbers for each colu. | Page Layout |