#1
|
|||
|
|||
Document Filename Generator for Referencing
Hi,
I work in an office that deals with a lot of client documents. Is there a way or software to create or generate an automatic filename or reference number for each documents that are created so that it will automatically inserted at the footer. For example, everytime i create a new document, a reference number will be automatically inserted in the footer. And this reference number will be used for database archiving. I appreciate your help on this. This would greatly organize all my documents. Thanks |
#2
|
||||
|
||||
Hi John,
If you insert a FILENAME field into the footer, that will reflect whatever the file's name is (you may need to do a Print Preview to get the field to update after saving with a new name). If the reference number is part of the filename, that will thus be included in the footer content.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Similarly, you could generate random numbers in a spreadsheet – I do this for unique topic IDs – and use them in a document property field.
|
#4
|
||||
|
||||
Hi eNGiNe,
I'm not sure what generating random numbers in Excel would achieve. The same could be done via a Document_New macro (ie without involving Excel). The danger with either approach, though, is that you could end up with multiple files containing the same randomly-generated numbers. FWIW, I've also posted a number of macros in the Word vba forum for sequentially numbering documents (typically invoices).
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Hi, thank you for your replies. I am already aware of the filename field. This will work but this would not create automatic unique reference number for the document and filename it.
Is there a way where there is like a software where you can set the parameters for your filenaming rules. For example, i have a client, and i am going to prepare for him a specific document, let's say a contract. Can I automatically create a reference filename for this document for easy retrieval in the future? |
#6
|
||||
|
||||
If you add the following code and a Custom Document Property named "RefNum" to the file template's 'thisDocument' code module, every new file you create from the template will be allocated an incrementing number:
Code:
Sub Document_New() Dim StrDefPath As String, StrTmpPath As String Dim RefFile As String, RefNum As String, Rng As Range 'Indicate the default save path for files created from this template, ' including the final '\'. StrTmpPath = "Filepath for documents based on this template" StrDefPath = Options.DefaultFilePath(wdDocumentsPath) Options.DefaultFilePath(wdDocumentsPath) = StrTmpPath RefFile = Options.DefaultFilePath(wdWorkgroupTemplatesPath) & "\RefNumber.txt" If Dir(RefFile) = "" Then 'If the Reference Number File file in the Word Workgroup folder, create it RefNum = 0 Open RefFile For Output As #1 Write #1, RefNum Close #1 End If 'Read the Reference Number File file in the Word Workgroup folder Open RefFile For Input As #1 Input #1, RefNum Close #1 ' Increment the Reference Number RefNum = RefNum + 1 DoEvents 'Update the Reference Number File file in the Word Workgroup folder Open RefFile For Output As #1 Write #1, RefNum Close #1 'Update the Reference Number in the document and prompt to save With ActiveDocument .CustomDocumentProperties("RefNum") = RefNum Application.ScreenUpdating = False For Each Rng In ActiveDocument.StoryRanges Rng.Fields.Update Next Application.ScreenUpdating = True With .Dialogs(wdDialogFileSaveAs) .Name = StrTmpPath & RefNum .Show End With End With Options.DefaultFilePath(wdDocumentsPath) = StrDefPath End Sub Sub ResetReferenceNumber() Dim RefFile As String, RefNum As String 'Re-set the Reference Number File file in the Word Workgroup folder RefFile = Options.DefaultFilePath(wdWorkgroupTemplatesPath) & "\RefNumber.txt" Open RefFile For Input As #1 Input #1, RefNum Close #1 RefNum = Trim(InputBox("What is the last valid Reference Number?" & vbCrLf & _ "The current number is: " & RefNum)) If IsNumeric(RefNum) Then If CInt(RefNum) = RefNum Then Open RefFile For Output As #1 Write #1, CInt(RefNum) Close #1 Exit Sub End If End If MsgBox "Re-numbering error, please try again." End Sub You could omit the Custom Document Property named "RefNum", but having it means the number remains with the document even if the filename is changed later on. If you want to give the file a default name that is more meaningful than just the reference number, you'll need to specify the rules for that. The code also includes a StrTmpPath variable, for nominating the default save path for files created from the template. I've also included some code to re-set the reference numbers.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Thanks Paul,
However, i am really a novice in terms like these. I have no experience in creating these codes and i am not sure how to use them. Does this mean that i will still have to manually enter a filename for each document? Is there a software or plug-in where it will create an automatic database or archive of all the documents created with the filename? For example, Contract A will be given a unique reference number or filename, like, Contract_101_John, where Contract= type of document, 101= reference number, and John=Client name. I find it time consuming to manually filename the documents and this is also prone to error. Thanks for your patience and continous help on this. |
#8
|
||||
|
||||
For macro installation and usage instructions, see: http://www.gmayor.com/installing_macro.htm.
For instructions on adding custom document properties to a document/template, see: http://office.microsoft.com/en-us/wo...010047524.aspx As indicated in my previous reply, the macro simply creates a sequential number and adds that to a custom document property. The macro then prompts the user to immediately save the document with that number. If you want anything fancier, you'll have to say exactly what the rules are for how a macro is supposed to work that out. Depending on what you want to do with the file, with the above approach, you can use a FILENAME field and/or a DOCPROPERTY field in the header/footer to display the reference number in the document.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
Well, using a spreadsheet instead of a macro means I can also maintain the spreadsheet as a record of which topic title uses which random number; and whenever I need to generate a new block of random numbers, I can sort the spreadsheet to weed out duplicates.
As m. Panhard observed, concerning an early gearbox: "it's rough and ready, but it works." <g> |
#10
|
||||
|
||||
Why do you suppose the numbers need to be random and how would you propose to get them into each new document? Manual transfer is unreliable and slow.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
In my case, as I said, I'm generating numbers for topic IDs; so I've decided to use random, and I also use a spreadsheet to put the tags I require round the numbers. Whether or not OP wants to use random numbers is entirely up to him, whether or not OP feels happy with copy/paste … also up to him. <g>
|
Tags |
filename, msword, reference |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Random number generator for Powerpoint 2011 | kala85 | PowerPoint | 0 | 11-19-2011 06:16 AM |
Save Filename using Document Text | Knawl | Word | 11 | 10-10-2011 03:00 AM |
Referencing text throughout a document | design | Word | 1 | 01-10-2011 03:54 PM |
Word: The document 'Filename' caused a serious error the last time ... | martincruise | Word | 0 | 02-25-2010 01:47 AM |
Document Generator | HJJ | Word | 0 | 08-12-2009 03:28 AM |