![]() |
#1
|
|||
|
|||
![]()
I'm creating a maintenance work-order system for a commercial property management company and need each work order to be sequentially numbered automatically upon opening. I've tried creating a field which ties to an original source document using the following:
{INCLUDETEXT "Drive:\\Filepath\\Filename.Extension"} This simply inserts the entire original document into the field. {INCLUDETEXT "Drive:\\Filepath\\Filename.Extension" \!} This does the same as the above and {INCLUDETEXT "Drive:\\Filepath\\Filename.Extension" "bookmark name"} This just shows a blank field with no data. The field code that I have in the original document is: seq workorder \# 00# \r000501 \* MERGEFORMAT What am I doing wrong here? ![]() |
#2
|
||||
|
||||
![]()
Hi mslearner,
That approach won't give you an automatically-incrementing work order number. The following macro (which I wrote for invoice generation) inserts and increments a number from a text (ini) file. It should serve your needs equally well. Code:
Private Sub Document_New() Application.ScreenUpdating = False Dim InvoiceFile As String, InvNum As String 'Save ini file in the Word startup folder. InvoiceFile = Options.DefaultFilePath(wdStartupPath) & "\Invoice.ini" 'or, by using the following line, the Workgroup folder 'InvoiceFile = Options.DefaultFilePath(wdWorkgroupTemplatesPath) & "\Invoice.ini" InvNum = System.PrivateProfileString(InvoiceFile, "InvoiceNumber", "InvNum") 'If there is no InvoiceNumber reference in the ini file 'Create one and set the number to 1, otherwise increment the number If InvNum = "" Then InvNum = 1 Else InvNum = InvNum + 1 End If System.PrivateProfileString(InvoiceFile, "InvoiceNumber", "InvNum") = InvNum With ActiveDocument 'Update the value stored in the document property .CustomDocumentProperties("InvNum") = InvNum 'Update the fields in the document .Fields.Update End With Application.ScreenUpdating = True End Sub Then, go to File|Info|Properties|Custom and add a document property named 'InvNum'. Next, in the body of the work order template, position the insertion point where you want the work order number to appear and press Ctrl-F9 to create a pair of field braces (ie '{}') and type 'DOCPROPERTY InvNum' between the field braces, thus '{DOCPROPERTY InvNum}'. If you want to force the work order # to display leading 0s (eg 01234), add '\# 0000' to the field code, thus: '{DOCPROPERTY InvNum \# 0000}'. Finally, save the template as a Word document Template (ie with a '.dot' (Word 2004 & earlier) or '.dotm' (Word 2007 & later) extension, via File|Save As), named 'Invoice' (or another suitable name). Now, whenever you want to create a new work order, simply go to File|New and select 'work order' (or your preferred name). You'll get an work order with the next available number. The last-used number is held in a file named 'Invoice.ini' in your Word Startup folder. In case you need it, there's a commented-out line to store the 'Invoice.ini' in your Word Workgroup folder instead, so that others in your workgroup can access it also. If you need to set the initial work order #, or reset it, you can do so manually, or use the following macro: Code:
Sub ResetOrderNumber() Dim InvoiceFile As String, InvNum As String InvoiceFile = Options.DefaultFilePath(wdStartupPath) & "\Invoice.ini" 'or, if using a Workgroup folder 'InvoiceFile = Options.DefaultFilePath(wdWorkgroupTemplatesPath) & "\Invoice.ini" InvNum = System.PrivateProfileString(InvoiceFile, "InvoiceNumber", "InvNum") InvNum = Trim(InputBox("What is the last valid Work Order Number?" & vbCrLf & _ "The current number is: " & InvNum)) If IsNumeric(InvNum) Then System.PrivateProfileString(InvoiceFile, "InvoiceNumber", "InvNum") = CInt(InvNum) End Else If InvNum = "" Then End End If MsgBox "Renumbering error, please try again." End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Thanks so much, this worked!
|
#4
|
|||
|
|||
![]()
Paul,
Im having trouble with setting up the system in Word 2007. I found and recorded the macro you posted but was unable to find where i could store the 'InvNum' system to make the numbering work. Thanks, April |
#5
|
||||
|
||||
![]()
Hi April,
You need to create a custom document property named 'InvNum'. IIRC, you get there in Word 2007 via: Alt-f > Prepare > Properties > Document Properties > Advanced Properties > Custom.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
![]()
User error... all working now. Excuse the interruption... normal service will now be resumed.
Last edited by raichea; 11-16-2012 at 10:02 AM. |
#7
|
|||
|
|||
![]()
What macros should I be adding this to?
|
#8
|
||||
|
||||
![]()
As clearly stated in post #2, you add it to the document template.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
![]()
I realize that this is an old thread but I've been searching hours for a way to do this on a template. I've tried your macro and it's not functioning for me.
I get a compile error on the first line: ambiguous name detected: Document_New. I'm using Word 2010 and am opening my template from within Word. Can you please help? Thank you! |
#10
|
||||
|
||||
![]()
The "ambiguous name detected: Document_New" message tells me that you already have a Document_New macro in the template. You can only have one such macro.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
![]()
If you give this macro a unique name, you can call it from the existing Document_New macro.
|
#12
|
||||
|
||||
![]()
I'd be wanting to know what the existing one does before recommending that approach. Even assuming a call is appropriate, it may be so in one part of the existing macro but not in another.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
![]() Quote:
The network location is a mapped drive on all machines. |
#14
|
|||
|
|||
![]()
This is the code I'm using.
Code:
Private Sub Document_New() Application.ScreenUpdating = False Dim InvoiceFile As String, InvNum As String InvoiceFile = Options.DefaultFilePath(wdDocumentsPath) = "N:\Engineering\ECN & ER Forms" & "\NUMBERS.ini" InvNum = System.PrivateProfileString(InvoiceFile, "InvoiceNumber", "InvNum") 'If there is no InvoiceNumber reference in the ini file 'Create one and set the number to 1, otherwise increment the number If InvNum = "" Then InvNum = 1 Else InvNum = InvNum + 1 End If System.PrivateProfileString(InvoiceFile, "InvoiceNumber", "InvNum") = InvNum With ActiveDocument 'Update the value stored in the document property .CustomDocumentProperties("InvNum") = InvNum 'Update the fields in the document .Fields.Update End With Application.ScreenUpdating = True End Sub NUMBERS.ini is stored in the same location as the form on the network. Getting the error shown below. Can someone assist? ![]() |
#15
|
||||
|
||||
![]()
For your situation, it would probably be best to create a Custom Document Property named 'InvNum' in the template, then use code like:
Code:
Private Sub Document_New() Application.ScreenUpdating = False Dim InvNum As String With ThisDocument InvNum = .CustomDocumentProperties("InvNum") + 1 .CustomDocumentProperties("InvNum") = InvNum '.Save End With With ActiveDocument 'Update the value stored in the document property .CustomDocumentProperties("InvNum") = InvNum 'Update the fields in the document .Fields.Update End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
gburya | Word VBA | 26 | 07-04-2017 03:29 PM |
![]() |
bobmard | Word | 8 | 08-24-2011 08:51 AM |
![]() |
frankdh | Word | 2 | 11-02-2010 10:59 AM |
Please help with Numbering a document with multiple letters. | DJReality213 | Office | 1 | 01-15-2010 05:56 PM |
Amend footer in multiple word docs? | compact | Word | 2 | 02-24-2009 09:40 AM |