Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Automatically creating file names for dicuments based on data ente
Is there a way to automatically created a file name to save a file created
from a template based upon the data entered in to the fields? -- agibson |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Automatically creating file names for dicuments based on data ente
Automatically?
Fields? Word version? It is certainly possible to save documents with a filename based on information in the document, but you need to tell us something about the document. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Is there a way to automatically created a file name to save a file created from a template based upon the data entered in to the fields? |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Automatically creating file names for dicuments based on data
Sorry not enough inf.
Im running word 2007 and have created a template. Ive got some feild codes in a template that include the following: Project, version number, title, document category (my own categories for different type of documents used in our company ie SOP, Finished Goods Specification, Record...). Currently staff have to duplicate some information in the file name as well as put it into the cover page of the document. The file name that we use is the sum of the above fields all in a particular order. For example the file name I want people to consistently use is: "Project_Name, Document_Title, Document_Type, Version_#". Is there a way that Word can automate the name of the file based on data entered into the data fields? Thanks -- agibson "Graham Mayor" wrote: Automatically? Fields? Word version? It is certainly possible to save documents with a filename based on information in the document, but you need to tell us something about the document. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Is there a way to automatically created a file name to save a file created from a template based upon the data entered in to the fields? |
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Automatically creating file names for dicuments based on data
Still not enough info. We cannot see your documents!
What kind of 'field codes' are these? How are they inserted into the document and how are they stored? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Sorry not enough inf. Im running word 2007 and have created a template. Ive got some feild codes in a template that include the following: Project, version number, title, document category (my own categories for different type of documents used in our company ie SOP, Finished Goods Specification, Record...). Currently staff have to duplicate some information in the file name as well as put it into the cover page of the document. The file name that we use is the sum of the above fields all in a particular order. For example the file name I want people to consistently use is: "Project_Name, Document_Title, Document_Type, Version_#". Is there a way that Word can automate the name of the file based on data entered into the data fields? Thanks Automatically? Fields? Word version? It is certainly possible to save documents with a filename based on information in the document, but you need to tell us something about the document. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Is there a way to automatically created a file name to save a file created from a template based upon the data entered in to the fields? |
#5
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Automatically creating file names for dicuments based on data
Hi thanks for persisting with me.
The field codes that I am using are from a word 2003 template I made are "text Form Field Codes". I'm currently got word 2007 on my computer. I have inserted the text fields into a table that is on the cover page of the template. Currently the template is stored on my C drive and the documents made from the template are in another folder (although that can change I suppose if it needs too). Hope I have answered your questions with enough detail. cheers -- agibson "Graham Mayor" wrote: Still not enough info. We cannot see your documents! What kind of 'field codes' are these? How are they inserted into the document and how are they stored? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Sorry not enough inf. Im running word 2007 and have created a template. Ive got some feild codes in a template that include the following: Project, version number, title, document category (my own categories for different type of documents used in our company ie SOP, Finished Goods Specification, Record...). Currently staff have to duplicate some information in the file name as well as put it into the cover page of the document. The file name that we use is the sum of the above fields all in a particular order. For example the file name I want people to consistently use is: "Project_Name, Document_Title, Document_Type, Version_#". Is there a way that Word can automate the name of the file based on data entered into the data fields? Thanks Automatically? Fields? Word version? It is certainly possible to save documents with a filename based on information in the document, but you need to tell us something about the document. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Is there a way to automatically created a file name to save a file created from a template based upon the data entered in to the fields? |
#6
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Automatically creating file names for dicuments based on data
Assuming your formfields bookmark names are those you indicate, then the following macro run on exit from the last of the relevant fields will save the document in the format you require in the current folder. Alternatively you can add the code to a toolbar save button, Sub FileSaveForm() Dim sValue1 As String Dim sValue2 As String Dim sValue3 As String Dim sValue4 As String Dim sFname As String With ActiveDocument sValue1 = .FormFields("Project_Name").Result sValue2 = .FormFields("Document_Title").Result sValue3 = .FormFields("Document_Type").Result sValue4 = .FormFields("Version").Result sFname = sValue1 & Chr(44) & sValue2 & Chr(44) _ & sValue3 & Chr(44) & "Version " & sValue4 & ".doc" If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If MsgBox sFname .SaveAs sFname End With End Sub http://www.gmayor.com/installing_macro.htm Note the macro does not check whether the filename already exists! -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Hi thanks for persisting with me. The field codes that I am using are from a word 2003 template I made are "text Form Field Codes". I'm currently got word 2007 on my computer. I have inserted the text fields into a table that is on the cover page of the template. Currently the template is stored on my C drive and the documents made from the template are in another folder (although that can change I suppose if it needs too). Hope I have answered your questions with enough detail. cheers Still not enough info. We cannot see your documents! What kind of 'field codes' are these? How are they inserted into the document and how are they stored? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Sorry not enough inf. Im running word 2007 and have created a template. Ive got some feild codes in a template that include the following: Project, version number, title, document category (my own categories for different type of documents used in our company ie SOP, Finished Goods Specification, Record...). Currently staff have to duplicate some information in the file name as well as put it into the cover page of the document. The file name that we use is the sum of the above fields all in a particular order. For example the file name I want people to consistently use is: "Project_Name, Document_Title, Document_Type, Version_#". Is there a way that Word can automate the name of the file based on data entered into the data fields? Thanks Automatically? Fields? Word version? It is certainly possible to save documents with a filename based on information in the document, but you need to tell us something about the document. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Is there a way to automatically created a file name to save a file created from a template based upon the data entered in to the fields? |
#7
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Automatically creating file names for dicuments based on data
You can remove the line MsgBox sFname - that was simply for testing.
-- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Graham Mayor wrote: Assuming your formfields bookmark names are those you indicate, then the following macro run on exit from the last of the relevant fields will save the document in the format you require in the current folder. Alternatively you can add the code to a toolbar save button, Sub FileSaveForm() Dim sValue1 As String Dim sValue2 As String Dim sValue3 As String Dim sValue4 As String Dim sFname As String With ActiveDocument sValue1 = .FormFields("Project_Name").Result sValue2 = .FormFields("Document_Title").Result sValue3 = .FormFields("Document_Type").Result sValue4 = .FormFields("Version").Result sFname = sValue1 & Chr(44) & sValue2 & Chr(44) _ & sValue3 & Chr(44) & "Version " & sValue4 & ".doc" If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If MsgBox sFname .SaveAs sFname End With End Sub http://www.gmayor.com/installing_macro.htm Note the macro does not check whether the filename already exists! Andrew wrote: Hi thanks for persisting with me. The field codes that I am using are from a word 2003 template I made are "text Form Field Codes". I'm currently got word 2007 on my computer. I have inserted the text fields into a table that is on the cover page of the template. Currently the template is stored on my C drive and the documents made from the template are in another folder (although that can change I suppose if it needs too). Hope I have answered your questions with enough detail. cheers Still not enough info. We cannot see your documents! What kind of 'field codes' are these? How are they inserted into the document and how are they stored? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Sorry not enough inf. Im running word 2007 and have created a template. Ive got some feild codes in a template that include the following: Project, version number, title, document category (my own categories for different type of documents used in our company ie SOP, Finished Goods Specification, Record...). Currently staff have to duplicate some information in the file name as well as put it into the cover page of the document. The file name that we use is the sum of the above fields all in a particular order. For example the file name I want people to consistently use is: "Project_Name, Document_Title, Document_Type, Version_#". Is there a way that Word can automate the name of the file based on data entered into the data fields? Thanks Automatically? Fields? Word version? It is certainly possible to save documents with a filename based on information in the document, but you need to tell us something about the document. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Is there a way to automatically created a file name to save a file created from a template based upon the data entered in to the fields? |
#8
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Automatically creating file names for dicuments based on data
thanks very much
-- agibson "Graham Mayor" wrote: You can remove the line MsgBox sFname - that was simply for testing. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Graham Mayor wrote: Assuming your formfields bookmark names are those you indicate, then the following macro run on exit from the last of the relevant fields will save the document in the format you require in the current folder. Alternatively you can add the code to a toolbar save button, Sub FileSaveForm() Dim sValue1 As String Dim sValue2 As String Dim sValue3 As String Dim sValue4 As String Dim sFname As String With ActiveDocument sValue1 = .FormFields("Project_Name").Result sValue2 = .FormFields("Document_Title").Result sValue3 = .FormFields("Document_Type").Result sValue4 = .FormFields("Version").Result sFname = sValue1 & Chr(44) & sValue2 & Chr(44) _ & sValue3 & Chr(44) & "Version " & sValue4 & ".doc" If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If MsgBox sFname .SaveAs sFname End With End Sub http://www.gmayor.com/installing_macro.htm Note the macro does not check whether the filename already exists! Andrew wrote: Hi thanks for persisting with me. The field codes that I am using are from a word 2003 template I made are "text Form Field Codes". I'm currently got word 2007 on my computer. I have inserted the text fields into a table that is on the cover page of the template. Currently the template is stored on my C drive and the documents made from the template are in another folder (although that can change I suppose if it needs too). Hope I have answered your questions with enough detail. cheers Still not enough info. We cannot see your documents! What kind of 'field codes' are these? How are they inserted into the document and how are they stored? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Sorry not enough inf. Im running word 2007 and have created a template. Ive got some feild codes in a template that include the following: Project, version number, title, document category (my own categories for different type of documents used in our company ie SOP, Finished Goods Specification, Record...). Currently staff have to duplicate some information in the file name as well as put it into the cover page of the document. The file name that we use is the sum of the above fields all in a particular order. For example the file name I want people to consistently use is: "Project_Name, Document_Title, Document_Type, Version_#". Is there a way that Word can automate the name of the file based on data entered into the data fields? Thanks Automatically? Fields? Word version? It is certainly possible to save documents with a filename based on information in the document, but you need to tell us something about the document. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Is there a way to automatically created a file name to save a file created from a template based upon the data entered in to the fields? |
#9
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Automatically creating file names for dicuments based on data
You are welcome
-- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: thanks very much You can remove the line MsgBox sFname - that was simply for testing. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Graham Mayor wrote: Assuming your formfields bookmark names are those you indicate, then the following macro run on exit from the last of the relevant fields will save the document in the format you require in the current folder. Alternatively you can add the code to a toolbar save button, Sub FileSaveForm() Dim sValue1 As String Dim sValue2 As String Dim sValue3 As String Dim sValue4 As String Dim sFname As String With ActiveDocument sValue1 = .FormFields("Project_Name").Result sValue2 = .FormFields("Document_Title").Result sValue3 = .FormFields("Document_Type").Result sValue4 = .FormFields("Version").Result sFname = sValue1 & Chr(44) & sValue2 & Chr(44) _ & sValue3 & Chr(44) & "Version " & sValue4 & ".doc" If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If MsgBox sFname .SaveAs sFname End With End Sub http://www.gmayor.com/installing_macro.htm Note the macro does not check whether the filename already exists! Andrew wrote: Hi thanks for persisting with me. The field codes that I am using are from a word 2003 template I made are "text Form Field Codes". I'm currently got word 2007 on my computer. I have inserted the text fields into a table that is on the cover page of the template. Currently the template is stored on my C drive and the documents made from the template are in another folder (although that can change I suppose if it needs too). Hope I have answered your questions with enough detail. cheers Still not enough info. We cannot see your documents! What kind of 'field codes' are these? How are they inserted into the document and how are they stored? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Sorry not enough inf. Im running word 2007 and have created a template. Ive got some feild codes in a template that include the following: Project, version number, title, document category (my own categories for different type of documents used in our company ie SOP, Finished Goods Specification, Record...). Currently staff have to duplicate some information in the file name as well as put it into the cover page of the document. The file name that we use is the sum of the above fields all in a particular order. For example the file name I want people to consistently use is: "Project_Name, Document_Title, Document_Type, Version_#". Is there a way that Word can automate the name of the file based on data entered into the data fields? Thanks Automatically? Fields? Word version? It is certainly possible to save documents with a filename based on information in the document, but you need to tell us something about the document. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Is there a way to automatically created a file name to save a file created from a template based upon the data entered in to the fields? |
#10
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Automatically creating file names for dicuments based on data
Hi GM, its taken me a while to learn macros to use the code that you gave me
a month ago but I just got it to work. its fantastic thanks -- agibson "Graham Mayor" wrote: You are welcome -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: thanks very much You can remove the line MsgBox sFname - that was simply for testing. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Graham Mayor wrote: Assuming your formfields bookmark names are those you indicate, then the following macro run on exit from the last of the relevant fields will save the document in the format you require in the current folder. Alternatively you can add the code to a toolbar save button, Sub FileSaveForm() Dim sValue1 As String Dim sValue2 As String Dim sValue3 As String Dim sValue4 As String Dim sFname As String With ActiveDocument sValue1 = .FormFields("Project_Name").Result sValue2 = .FormFields("Document_Title").Result sValue3 = .FormFields("Document_Type").Result sValue4 = .FormFields("Version").Result sFname = sValue1 & Chr(44) & sValue2 & Chr(44) _ & sValue3 & Chr(44) & "Version " & sValue4 & ".doc" If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If MsgBox sFname .SaveAs sFname End With End Sub http://www.gmayor.com/installing_macro.htm Note the macro does not check whether the filename already exists! Andrew wrote: Hi thanks for persisting with me. The field codes that I am using are from a word 2003 template I made are "text Form Field Codes". I'm currently got word 2007 on my computer. I have inserted the text fields into a table that is on the cover page of the template. Currently the template is stored on my C drive and the documents made from the template are in another folder (although that can change I suppose if it needs too). Hope I have answered your questions with enough detail. cheers Still not enough info. We cannot see your documents! What kind of 'field codes' are these? How are they inserted into the document and how are they stored? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Sorry not enough inf. Im running word 2007 and have created a template. Ive got some feild codes in a template that include the following: Project, version number, title, document category (my own categories for different type of documents used in our company ie SOP, Finished Goods Specification, Record...). Currently staff have to duplicate some information in the file name as well as put it into the cover page of the document. The file name that we use is the sum of the above fields all in a particular order. For example the file name I want people to consistently use is: "Project_Name, Document_Title, Document_Type, Version_#". Is there a way that Word can automate the name of the file based on data entered into the data fields? Thanks Automatically? Fields? Word version? It is certainly possible to save documents with a filename based on information in the document, but you need to tell us something about the document. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Is there a way to automatically created a file name to save a file created from a template based upon the data entered in to the fields? |
#11
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Automatically creating file names for dicuments based on data
You should have said that you were having problems?
Glad you got there in the end. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Hi GM, its taken me a while to learn macros to use the code that you gave me a month ago but I just got it to work. its fantastic thanks You are welcome -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: thanks very much You can remove the line MsgBox sFname - that was simply for testing. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Graham Mayor wrote: Assuming your formfields bookmark names are those you indicate, then the following macro run on exit from the last of the relevant fields will save the document in the format you require in the current folder. Alternatively you can add the code to a toolbar save button, Sub FileSaveForm() Dim sValue1 As String Dim sValue2 As String Dim sValue3 As String Dim sValue4 As String Dim sFname As String With ActiveDocument sValue1 = .FormFields("Project_Name").Result sValue2 = .FormFields("Document_Title").Result sValue3 = .FormFields("Document_Type").Result sValue4 = .FormFields("Version").Result sFname = sValue1 & Chr(44) & sValue2 & Chr(44) _ & sValue3 & Chr(44) & "Version " & sValue4 & ".doc" If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If MsgBox sFname .SaveAs sFname End With End Sub http://www.gmayor.com/installing_macro.htm Note the macro does not check whether the filename already exists! Andrew wrote: Hi thanks for persisting with me. The field codes that I am using are from a word 2003 template I made are "text Form Field Codes". I'm currently got word 2007 on my computer. I have inserted the text fields into a table that is on the cover page of the template. Currently the template is stored on my C drive and the documents made from the template are in another folder (although that can change I suppose if it needs too). Hope I have answered your questions with enough detail. cheers Still not enough info. We cannot see your documents! What kind of 'field codes' are these? How are they inserted into the document and how are they stored? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Sorry not enough inf. Im running word 2007 and have created a template. Ive got some feild codes in a template that include the following: Project, version number, title, document category (my own categories for different type of documents used in our company ie SOP, Finished Goods Specification, Record...). Currently staff have to duplicate some information in the file name as well as put it into the cover page of the document. The file name that we use is the sum of the above fields all in a particular order. For example the file name I want people to consistently use is: "Project_Name, Document_Title, Document_Type, Version_#". Is there a way that Word can automate the name of the file based on data entered into the data fields? Thanks Automatically? Fields? Word version? It is certainly possible to save documents with a filename based on information in the document, but you need to tell us something about the document. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Is there a way to automatically created a file name to save a file created from a template based upon the data entered in to the fields? |
#12
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Automatically creating file names for dicuments based on data
Hello again,
If I could trouble you for a question please. I've got the macro running as I previously have said. I've even added an extra Value, and its running great. However all the values are in the tile are only separated by a comma - no space between them. It makes it kinda hard to read. See below C:\Users\Andrew\Documents\D_1234,Cool_QMS,test_doc ument,SOP,V_1.00.doc Is there a way to put a space between each sValue or some other type of charater. I tried " " on the off chance that it might work but got an error. C:\Users\Andrew\Documents\D_1234, Cool_QMS, test_document, SOP, V_1.00.doc -- agibson "Graham Mayor" wrote: You should have said that you were having problems? Glad you got there in the end. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Hi GM, its taken me a while to learn macros to use the code that you gave me a month ago but I just got it to work. its fantastic thanks You are welcome -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: thanks very much You can remove the line MsgBox sFname - that was simply for testing. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Graham Mayor wrote: Assuming your formfields bookmark names are those you indicate, then the following macro run on exit from the last of the relevant fields will save the document in the format you require in the current folder. Alternatively you can add the code to a toolbar save button, Sub FileSaveForm() Dim sValue1 As String Dim sValue2 As String Dim sValue3 As String Dim sValue4 As String Dim sFname As String With ActiveDocument sValue1 = .FormFields("Project_Name").Result sValue2 = .FormFields("Document_Title").Result sValue3 = .FormFields("Document_Type").Result sValue4 = .FormFields("Version").Result sFname = sValue1 & Chr(44) & sValue2 & Chr(44) _ & sValue3 & Chr(44) & "Version " & sValue4 & ".doc" If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If MsgBox sFname .SaveAs sFname End With End Sub http://www.gmayor.com/installing_macro.htm Note the macro does not check whether the filename already exists! Andrew wrote: Hi thanks for persisting with me. The field codes that I am using are from a word 2003 template I made are "text Form Field Codes". I'm currently got word 2007 on my computer. I have inserted the text fields into a table that is on the cover page of the template. Currently the template is stored on my C drive and the documents made from the template are in another folder (although that can change I suppose if it needs too). Hope I have answered your questions with enough detail. cheers Still not enough info. We cannot see your documents! What kind of 'field codes' are these? How are they inserted into the document and how are they stored? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Sorry not enough inf. Im running word 2007 and have created a template. Ive got some feild codes in a template that include the following: Project, version number, title, document category (my own categories for different type of documents used in our company ie SOP, Finished Goods Specification, Record...). Currently staff have to duplicate some information in the file name as well as put it into the cover page of the document. The file name that we use is the sum of the above fields all in a particular order. For example the file name I want people to consistently use is: "Project_Name, Document_Title, Document_Type, Version_#". Is there a way that Word can automate the name of the file based on data entered into the data fields? Thanks Automatically? Fields? Word version? It is certainly possible to save documents with a filename based on information in the document, but you need to tell us something about the document. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Is there a way to automatically created a file name to save a file created from a template based upon the data entered in to the fields? |
#13
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Automatically creating file names for dicuments based on data
The macro was originally written to remove spaces and replace them with
underscores using the section If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If and I had deliberatly refrained from adding spaces after the commas as I assumed from your original post that you didn't want them. So you can start by losing that bit. Next the commas are inserted with & Chr(44) &. If you want a space after the comma you could simply extend each occurrence to & Chr(44) & CHR(32) & or & Chr(44) & " " & but if you leave If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If those spaces will be replaced with underscores. If you want the underscores in the field results, you can add them to the individual field results eg sValue1 = .FormFields("Project_Name").Result If InStr(1, sValue1, " ") 0 Then sValue1 = Replace(sValue1, " ", "_") End If sValue2 = .FormFields("Document_Title").Result If InStr(1, sValue2, " ") 0 Then sValue2 = Replace(sValue2, " ", "_") End If sValue3 = .FormFields("Document_Type").Result If InStr(1, sValue3, " ") 0 Then sValue3 = Replace(sValue3, " ", "_") End If sValue4 = .FormFields("Version").Result If InStr(1, sValue4, " ") 0 Then sValue4 = Replace(sValue4, " ", "_") End If If you find it simpler to manipulate you can take this a step further and add the commas and spaces to each string before assembling them in the sFname string eg With ActiveDocument sValue1 = .FormFields("Project_Name").Result If InStr(1, sValue1, " ") 0 Then 'Replace the user entered space with an underscore sValue1 = Replace(sValue1, " ", "_") 'add the comma and space sValue1 = sValue1 & Chr(44) & Chr(32) End If sValue2 = .FormFields("Document_Title").Result If InStr(1, sValue2, " ") 0 Then sValue2 = Replace(sValue2, " ", "_") sValue2 = sValue2 & Chr(44) & Chr(32) End If sValue3 = .FormFields("Document_Type").Result If InStr(1, sValue3, " ") 0 Then sValue3 = Replace(sValue3, " ", "_") sValue3 = sValue3 & Chr(44) & Chr(32) End If sValue4 = .FormFields("Version").Result If InStr(1, sValue4, " ") 0 Then sValue4 = Replace(sValue4, " ", "_") sValue4 = sValue4 & Chr(44) & Chr(32) End If sFname = sValue1 & sValue2 _ & sValue3 & "Version " & sValue4 & ".doc" .SaveAs sFname End With and if you don't want underscores at all it is even simpler: With ActiveDocument sValue1 = .FormFields("Project_Name").Result sValue1 = sValue1 & Chr(44) & Chr(32) sValue2 = .FormFields("Document_Title").Result sValue2 = sValue2 & Chr(44) & Chr(32) sValue3 = .FormFields("Document_Type").Result sValue3 = sValue3 & Chr(44) & Chr(32) sValue4 = .FormFields("Version").Result sValue4 = sValue4 & Chr(44) & Chr(32) sFname = sValue1 & sValue2 _ & sValue3 & "Version " & sValue4 & ".doc" .SaveAs sFname End With End Sub Does that help? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Hello again, If I could trouble you for a question please. I've got the macro running as I previously have said. I've even added an extra Value, and its running great. However all the values are in the tile are only separated by a comma - no space between them. It makes it kinda hard to read. See below C:\Users\Andrew\Documents\D_1234,Cool_QMS,test_doc ument,SOP,V_1.00.doc Is there a way to put a space between each sValue or some other type of charater. I tried " " on the off chance that it might work but got an error. C:\Users\Andrew\Documents\D_1234, Cool_QMS, test_document, SOP, V_1.00.doc You should have said that you were having problems? Glad you got there in the end. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Hi GM, its taken me a while to learn macros to use the code that you gave me a month ago but I just got it to work. its fantastic thanks You are welcome -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: thanks very much You can remove the line MsgBox sFname - that was simply for testing. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Graham Mayor wrote: Assuming your formfields bookmark names are those you indicate, then the following macro run on exit from the last of the relevant fields will save the document in the format you require in the current folder. Alternatively you can add the code to a toolbar save button, Sub FileSaveForm() Dim sValue1 As String Dim sValue2 As String Dim sValue3 As String Dim sValue4 As String Dim sFname As String With ActiveDocument sValue1 = .FormFields("Project_Name").Result sValue2 = .FormFields("Document_Title").Result sValue3 = .FormFields("Document_Type").Result sValue4 = .FormFields("Version").Result sFname = sValue1 & Chr(44) & sValue2 & Chr(44) _ & sValue3 & Chr(44) & "Version " & sValue4 & ".doc" If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If MsgBox sFname .SaveAs sFname End With End Sub http://www.gmayor.com/installing_macro.htm Note the macro does not check whether the filename already exists! Andrew wrote: Hi thanks for persisting with me. The field codes that I am using are from a word 2003 template I made are "text Form Field Codes". I'm currently got word 2007 on my computer. I have inserted the text fields into a table that is on the cover page of the template. Currently the template is stored on my C drive and the documents made from the template are in another folder (although that can change I suppose if it needs too). Hope I have answered your questions with enough detail. cheers Still not enough info. We cannot see your documents! What kind of 'field codes' are these? How are they inserted into the document and how are they stored? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Sorry not enough inf. Im running word 2007 and have created a template. Ive got some feild codes in a template that include the following: Project, version number, title, document category (my own categories for different type of documents used in our company ie SOP, Finished Goods Specification, Record...). Currently staff have to duplicate some information in the file name as well as put it into the cover page of the document. The file name that we use is the sum of the above fields all in a particular order. For example the file name I want people to consistently use is: "Project_Name, Document_Title, Document_Type, Version_#". Is there a way that Word can automate the name of the file based on data entered into the data fields? Thanks Automatically? Fields? Word version? It is certainly possible to save documents with a filename based on information in the document, but you need to tell us something about the document. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Is there a way to automatically created a file name to save a file created from a template based upon the data entered in to the fields? |
#14
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Automatically creating file names for dicuments based on data
Got it exactly how I wanted it,
thanks for the detailed answer -- agibson "Graham Mayor" wrote: The macro was originally written to remove spaces and replace them with underscores using the section If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If and I had deliberatly refrained from adding spaces after the commas as I assumed from your original post that you didn't want them. So you can start by losing that bit. Next the commas are inserted with & Chr(44) &. If you want a space after the comma you could simply extend each occurrence to & Chr(44) & CHR(32) & or & Chr(44) & " " & but if you leave If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If those spaces will be replaced with underscores. If you want the underscores in the field results, you can add them to the individual field results eg sValue1 = .FormFields("Project_Name").Result If InStr(1, sValue1, " ") 0 Then sValue1 = Replace(sValue1, " ", "_") End If sValue2 = .FormFields("Document_Title").Result If InStr(1, sValue2, " ") 0 Then sValue2 = Replace(sValue2, " ", "_") End If sValue3 = .FormFields("Document_Type").Result If InStr(1, sValue3, " ") 0 Then sValue3 = Replace(sValue3, " ", "_") End If sValue4 = .FormFields("Version").Result If InStr(1, sValue4, " ") 0 Then sValue4 = Replace(sValue4, " ", "_") End If If you find it simpler to manipulate you can take this a step further and add the commas and spaces to each string before assembling them in the sFname string eg With ActiveDocument sValue1 = .FormFields("Project_Name").Result If InStr(1, sValue1, " ") 0 Then 'Replace the user entered space with an underscore sValue1 = Replace(sValue1, " ", "_") 'add the comma and space sValue1 = sValue1 & Chr(44) & Chr(32) End If sValue2 = .FormFields("Document_Title").Result If InStr(1, sValue2, " ") 0 Then sValue2 = Replace(sValue2, " ", "_") sValue2 = sValue2 & Chr(44) & Chr(32) End If sValue3 = .FormFields("Document_Type").Result If InStr(1, sValue3, " ") 0 Then sValue3 = Replace(sValue3, " ", "_") sValue3 = sValue3 & Chr(44) & Chr(32) End If sValue4 = .FormFields("Version").Result If InStr(1, sValue4, " ") 0 Then sValue4 = Replace(sValue4, " ", "_") sValue4 = sValue4 & Chr(44) & Chr(32) End If sFname = sValue1 & sValue2 _ & sValue3 & "Version " & sValue4 & ".doc" .SaveAs sFname End With and if you don't want underscores at all it is even simpler: With ActiveDocument sValue1 = .FormFields("Project_Name").Result sValue1 = sValue1 & Chr(44) & Chr(32) sValue2 = .FormFields("Document_Title").Result sValue2 = sValue2 & Chr(44) & Chr(32) sValue3 = .FormFields("Document_Type").Result sValue3 = sValue3 & Chr(44) & Chr(32) sValue4 = .FormFields("Version").Result sValue4 = sValue4 & Chr(44) & Chr(32) sFname = sValue1 & sValue2 _ & sValue3 & "Version " & sValue4 & ".doc" .SaveAs sFname End With End Sub Does that help? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Hello again, If I could trouble you for a question please. I've got the macro running as I previously have said. I've even added an extra Value, and its running great. However all the values are in the tile are only separated by a comma - no space between them. It makes it kinda hard to read. See below C:\Users\Andrew\Documents\D_1234,Cool_QMS,test_doc ument,SOP,V_1.00.doc Is there a way to put a space between each sValue or some other type of charater. I tried " " on the off chance that it might work but got an error. C:\Users\Andrew\Documents\D_1234, Cool_QMS, test_document, SOP, V_1.00.doc You should have said that you were having problems? Glad you got there in the end. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Hi GM, its taken me a while to learn macros to use the code that you gave me a month ago but I just got it to work. its fantastic thanks You are welcome -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: thanks very much You can remove the line MsgBox sFname - that was simply for testing. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Graham Mayor wrote: Assuming your formfields bookmark names are those you indicate, then the following macro run on exit from the last of the relevant fields will save the document in the format you require in the current folder. Alternatively you can add the code to a toolbar save button, Sub FileSaveForm() Dim sValue1 As String Dim sValue2 As String Dim sValue3 As String Dim sValue4 As String Dim sFname As String With ActiveDocument sValue1 = .FormFields("Project_Name").Result sValue2 = .FormFields("Document_Title").Result sValue3 = .FormFields("Document_Type").Result sValue4 = .FormFields("Version").Result sFname = sValue1 & Chr(44) & sValue2 & Chr(44) _ & sValue3 & Chr(44) & "Version " & sValue4 & ".doc" If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If MsgBox sFname .SaveAs sFname End With End Sub http://www.gmayor.com/installing_macro.htm Note the macro does not check whether the filename already exists! Andrew wrote: Hi thanks for persisting with me. The field codes that I am using are from a word 2003 template I made are "text Form Field Codes". I'm currently got word 2007 on my computer. I have inserted the text fields into a table that is on the cover page of the template. Currently the template is stored on my C drive and the documents made from the template are in another folder (although that can change I suppose if it needs too). Hope I have answered your questions with enough detail. cheers Still not enough info. We cannot see your documents! What kind of 'field codes' are these? How are they inserted into the document and how are they stored? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Sorry not enough inf. Im running word 2007 and have created a template. Ive got some feild codes in a template that include the following: Project, version number, title, document category (my own categories for different type of documents used in our company ie SOP, Finished Goods Specification, Record...). Currently staff have to duplicate some information in the file name as well as put it into the cover page of the document. The file name that we use is the sum of the above fields all in a particular order. For example the file name I want people to consistently use is: "Project_Name, Document_Title, Document_Type, Version_#". Is there a way that Word can automate the name of the file based on data entered into the data fields? Thanks Automatically? Fields? Word version? It is certainly possible to save documents with a filename based on information in the document, but you need to tell us something about the document. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Is there a way to automatically created a file name to save a file created from a template based upon the data entered in to the fields? |
#15
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Automatically creating file names for dicuments based on data
Excellent
-- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Got it exactly how I wanted it, thanks for the detailed answer The macro was originally written to remove spaces and replace them with underscores using the section If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If and I had deliberatly refrained from adding spaces after the commas as I assumed from your original post that you didn't want them. So you can start by losing that bit. Next the commas are inserted with & Chr(44) &. If you want a space after the comma you could simply extend each occurrence to & Chr(44) & CHR(32) & or & Chr(44) & " " & but if you leave If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If those spaces will be replaced with underscores. If you want the underscores in the field results, you can add them to the individual field results eg sValue1 = .FormFields("Project_Name").Result If InStr(1, sValue1, " ") 0 Then sValue1 = Replace(sValue1, " ", "_") End If sValue2 = .FormFields("Document_Title").Result If InStr(1, sValue2, " ") 0 Then sValue2 = Replace(sValue2, " ", "_") End If sValue3 = .FormFields("Document_Type").Result If InStr(1, sValue3, " ") 0 Then sValue3 = Replace(sValue3, " ", "_") End If sValue4 = .FormFields("Version").Result If InStr(1, sValue4, " ") 0 Then sValue4 = Replace(sValue4, " ", "_") End If If you find it simpler to manipulate you can take this a step further and add the commas and spaces to each string before assembling them in the sFname string eg With ActiveDocument sValue1 = .FormFields("Project_Name").Result If InStr(1, sValue1, " ") 0 Then 'Replace the user entered space with an underscore sValue1 = Replace(sValue1, " ", "_") 'add the comma and space sValue1 = sValue1 & Chr(44) & Chr(32) End If sValue2 = .FormFields("Document_Title").Result If InStr(1, sValue2, " ") 0 Then sValue2 = Replace(sValue2, " ", "_") sValue2 = sValue2 & Chr(44) & Chr(32) End If sValue3 = .FormFields("Document_Type").Result If InStr(1, sValue3, " ") 0 Then sValue3 = Replace(sValue3, " ", "_") sValue3 = sValue3 & Chr(44) & Chr(32) End If sValue4 = .FormFields("Version").Result If InStr(1, sValue4, " ") 0 Then sValue4 = Replace(sValue4, " ", "_") sValue4 = sValue4 & Chr(44) & Chr(32) End If sFname = sValue1 & sValue2 _ & sValue3 & "Version " & sValue4 & ".doc" .SaveAs sFname End With and if you don't want underscores at all it is even simpler: With ActiveDocument sValue1 = .FormFields("Project_Name").Result sValue1 = sValue1 & Chr(44) & Chr(32) sValue2 = .FormFields("Document_Title").Result sValue2 = sValue2 & Chr(44) & Chr(32) sValue3 = .FormFields("Document_Type").Result sValue3 = sValue3 & Chr(44) & Chr(32) sValue4 = .FormFields("Version").Result sValue4 = sValue4 & Chr(44) & Chr(32) sFname = sValue1 & sValue2 _ & sValue3 & "Version " & sValue4 & ".doc" .SaveAs sFname End With End Sub Does that help? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Hello again, If I could trouble you for a question please. I've got the macro running as I previously have said. I've even added an extra Value, and its running great. However all the values are in the tile are only separated by a comma - no space between them. It makes it kinda hard to read. See below C:\Users\Andrew\Documents\D_1234,Cool_QMS,test_doc ument,SOP,V_1.00.doc Is there a way to put a space between each sValue or some other type of charater. I tried " " on the off chance that it might work but got an error. C:\Users\Andrew\Documents\D_1234, Cool_QMS, test_document, SOP, V_1.00.doc You should have said that you were having problems? Glad you got there in the end. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Hi GM, its taken me a while to learn macros to use the code that you gave me a month ago but I just got it to work. its fantastic thanks You are welcome -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: thanks very much You can remove the line MsgBox sFname - that was simply for testing. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Graham Mayor wrote: Assuming your formfields bookmark names are those you indicate, then the following macro run on exit from the last of the relevant fields will save the document in the format you require in the current folder. Alternatively you can add the code to a toolbar save button, Sub FileSaveForm() Dim sValue1 As String Dim sValue2 As String Dim sValue3 As String Dim sValue4 As String Dim sFname As String With ActiveDocument sValue1 = .FormFields("Project_Name").Result sValue2 = .FormFields("Document_Title").Result sValue3 = .FormFields("Document_Type").Result sValue4 = .FormFields("Version").Result sFname = sValue1 & Chr(44) & sValue2 & Chr(44) _ & sValue3 & Chr(44) & "Version " & sValue4 & ".doc" If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If MsgBox sFname .SaveAs sFname End With End Sub http://www.gmayor.com/installing_macro.htm Note the macro does not check whether the filename already exists! Andrew wrote: Hi thanks for persisting with me. The field codes that I am using are from a word 2003 template I made are "text Form Field Codes". I'm currently got word 2007 on my computer. I have inserted the text fields into a table that is on the cover page of the template. Currently the template is stored on my C drive and the documents made from the template are in another folder (although that can change I suppose if it needs too). Hope I have answered your questions with enough detail. cheers Still not enough info. We cannot see your documents! What kind of 'field codes' are these? How are they inserted into the document and how are they stored? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Sorry not enough inf. Im running word 2007 and have created a template. Ive got some feild codes in a template that include the following: Project, version number, title, document category (my own categories for different type of documents used in our company ie SOP, Finished Goods Specification, Record...). Currently staff have to duplicate some information in the file name as well as put it into the cover page of the document. The file name that we use is the sum of the above fields all in a particular order. For example the file name I want people to consistently use is: "Project_Name, Document_Title, Document_Type, Version_#". Is there a way that Word can automate the name of the file based on data entered into the data fields? Thanks Automatically? Fields? Word version? It is certainly possible to save documents with a filename based on information in the document, but you need to tell us something about the document. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Is there a way to automatically created a file name to save a file created from a template based upon the data entered in to the fields? |
#16
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Automatically creating file names for dicuments based on data
I've been using this macro for some time and its working fine. however with
word 2007 and the excellent "properties" section I think it would be better to use these fields instead of "form fields". Is this a simple change? thanks -- agibson "Graham Mayor" wrote: Excellent -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Got it exactly how I wanted it, thanks for the detailed answer The macro was originally written to remove spaces and replace them with underscores using the section If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If and I had deliberatly refrained from adding spaces after the commas as I assumed from your original post that you didn't want them. So you can start by losing that bit. Next the commas are inserted with & Chr(44) &. If you want a space after the comma you could simply extend each occurrence to & Chr(44) & CHR(32) & or & Chr(44) & " " & but if you leave If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If those spaces will be replaced with underscores. If you want the underscores in the field results, you can add them to the individual field results eg sValue1 = .FormFields("Project_Name").Result If InStr(1, sValue1, " ") 0 Then sValue1 = Replace(sValue1, " ", "_") End If sValue2 = .FormFields("Document_Title").Result If InStr(1, sValue2, " ") 0 Then sValue2 = Replace(sValue2, " ", "_") End If sValue3 = .FormFields("Document_Type").Result If InStr(1, sValue3, " ") 0 Then sValue3 = Replace(sValue3, " ", "_") End If sValue4 = .FormFields("Version").Result If InStr(1, sValue4, " ") 0 Then sValue4 = Replace(sValue4, " ", "_") End If If you find it simpler to manipulate you can take this a step further and add the commas and spaces to each string before assembling them in the sFname string eg With ActiveDocument sValue1 = .FormFields("Project_Name").Result If InStr(1, sValue1, " ") 0 Then 'Replace the user entered space with an underscore sValue1 = Replace(sValue1, " ", "_") 'add the comma and space sValue1 = sValue1 & Chr(44) & Chr(32) End If sValue2 = .FormFields("Document_Title").Result If InStr(1, sValue2, " ") 0 Then sValue2 = Replace(sValue2, " ", "_") sValue2 = sValue2 & Chr(44) & Chr(32) End If sValue3 = .FormFields("Document_Type").Result If InStr(1, sValue3, " ") 0 Then sValue3 = Replace(sValue3, " ", "_") sValue3 = sValue3 & Chr(44) & Chr(32) End If sValue4 = .FormFields("Version").Result If InStr(1, sValue4, " ") 0 Then sValue4 = Replace(sValue4, " ", "_") sValue4 = sValue4 & Chr(44) & Chr(32) End If sFname = sValue1 & sValue2 _ & sValue3 & "Version " & sValue4 & ".doc" .SaveAs sFname End With and if you don't want underscores at all it is even simpler: With ActiveDocument sValue1 = .FormFields("Project_Name").Result sValue1 = sValue1 & Chr(44) & Chr(32) sValue2 = .FormFields("Document_Title").Result sValue2 = sValue2 & Chr(44) & Chr(32) sValue3 = .FormFields("Document_Type").Result sValue3 = sValue3 & Chr(44) & Chr(32) sValue4 = .FormFields("Version").Result sValue4 = sValue4 & Chr(44) & Chr(32) sFname = sValue1 & sValue2 _ & sValue3 & "Version " & sValue4 & ".doc" .SaveAs sFname End With End Sub Does that help? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Hello again, If I could trouble you for a question please. I've got the macro running as I previously have said. I've even added an extra Value, and its running great. However all the values are in the tile are only separated by a comma - no space between them. It makes it kinda hard to read. See below C:\Users\Andrew\Documents\D_1234,Cool_QMS,test_doc ument,SOP,V_1.00.doc Is there a way to put a space between each sValue or some other type of charater. I tried " " on the off chance that it might work but got an error. C:\Users\Andrew\Documents\D_1234, Cool_QMS, test_document, SOP, V_1.00.doc You should have said that you were having problems? Glad you got there in the end. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Hi GM, its taken me a while to learn macros to use the code that you gave me a month ago but I just got it to work. its fantastic thanks You are welcome -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: thanks very much You can remove the line MsgBox sFname - that was simply for testing. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Graham Mayor wrote: Assuming your formfields bookmark names are those you indicate, then the following macro run on exit from the last of the relevant fields will save the document in the format you require in the current folder. Alternatively you can add the code to a toolbar save button, Sub FileSaveForm() Dim sValue1 As String Dim sValue2 As String Dim sValue3 As String Dim sValue4 As String Dim sFname As String With ActiveDocument sValue1 = .FormFields("Project_Name").Result sValue2 = .FormFields("Document_Title").Result sValue3 = .FormFields("Document_Type").Result sValue4 = .FormFields("Version").Result sFname = sValue1 & Chr(44) & sValue2 & Chr(44) _ & sValue3 & Chr(44) & "Version " & sValue4 & ".doc" If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If MsgBox sFname .SaveAs sFname End With End Sub http://www.gmayor.com/installing_macro.htm Note the macro does not check whether the filename already exists! Andrew wrote: Hi thanks for persisting with me. The field codes that I am using are from a word 2003 template I made are "text Form Field Codes". I'm currently got word 2007 on my computer. I have inserted the text fields into a table that is on the cover page of the template. Currently the template is stored on my C drive and the documents made from the template are in another folder (although that can change I suppose if it needs too). Hope I have answered your questions with enough detail. cheers Still not enough info. We cannot see your documents! What kind of 'field codes' are these? How are they inserted into the document and how are they stored? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Sorry not enough inf. Im running word 2007 and have created a template. Ive got some feild codes in a template that include the following: Project, version number, title, document category (my own categories for different type of documents used in our company ie SOP, Finished Goods Specification, Record...). Currently staff have to duplicate some information in the file name as well as put it into the cover page of the document. The file name that we use is the sum of the above fields all in a particular order. For example the file name I want people to consistently use is: "Project_Name, Document_Title, Document_Type, Version_#". Is there a way that Word can automate the name of the file based on data entered into the data fields? Thanks Automatically? Fields? Word version? It is certainly possible to save documents with a filename based on information in the document, but you need to tell us something about the document. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org |
#17
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Automatically creating file names for dicuments based on data
Word has always had the properties section, however it was you who indicated
that you wanted to extract the information from form fields, after much pressing on the topic. If you want to extract the data from the document property fields then that too is possible, but inserting the data into the doc property fields in the first place is less convenient than using form field data that is already in your document, when you want an automated process. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: I've been using this macro for some time and its working fine. however with word 2007 and the excellent "properties" section I think it would be better to use these fields instead of "form fields". Is this a simple change? thanks Excellent -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Got it exactly how I wanted it, thanks for the detailed answer The macro was originally written to remove spaces and replace them with underscores using the section If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If and I had deliberatly refrained from adding spaces after the commas as I assumed from your original post that you didn't want them. So you can start by losing that bit. Next the commas are inserted with & Chr(44) &. If you want a space after the comma you could simply extend each occurrence to & Chr(44) & CHR(32) & or & Chr(44) & " " & but if you leave If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If those spaces will be replaced with underscores. If you want the underscores in the field results, you can add them to the individual field results eg sValue1 = .FormFields("Project_Name").Result If InStr(1, sValue1, " ") 0 Then sValue1 = Replace(sValue1, " ", "_") End If sValue2 = .FormFields("Document_Title").Result If InStr(1, sValue2, " ") 0 Then sValue2 = Replace(sValue2, " ", "_") End If sValue3 = .FormFields("Document_Type").Result If InStr(1, sValue3, " ") 0 Then sValue3 = Replace(sValue3, " ", "_") End If sValue4 = .FormFields("Version").Result If InStr(1, sValue4, " ") 0 Then sValue4 = Replace(sValue4, " ", "_") End If If you find it simpler to manipulate you can take this a step further and add the commas and spaces to each string before assembling them in the sFname string eg With ActiveDocument sValue1 = .FormFields("Project_Name").Result If InStr(1, sValue1, " ") 0 Then 'Replace the user entered space with an underscore sValue1 = Replace(sValue1, " ", "_") 'add the comma and space sValue1 = sValue1 & Chr(44) & Chr(32) End If sValue2 = .FormFields("Document_Title").Result If InStr(1, sValue2, " ") 0 Then sValue2 = Replace(sValue2, " ", "_") sValue2 = sValue2 & Chr(44) & Chr(32) End If sValue3 = .FormFields("Document_Type").Result If InStr(1, sValue3, " ") 0 Then sValue3 = Replace(sValue3, " ", "_") sValue3 = sValue3 & Chr(44) & Chr(32) End If sValue4 = .FormFields("Version").Result If InStr(1, sValue4, " ") 0 Then sValue4 = Replace(sValue4, " ", "_") sValue4 = sValue4 & Chr(44) & Chr(32) End If sFname = sValue1 & sValue2 _ & sValue3 & "Version " & sValue4 & ".doc" .SaveAs sFname End With and if you don't want underscores at all it is even simpler: With ActiveDocument sValue1 = .FormFields("Project_Name").Result sValue1 = sValue1 & Chr(44) & Chr(32) sValue2 = .FormFields("Document_Title").Result sValue2 = sValue2 & Chr(44) & Chr(32) sValue3 = .FormFields("Document_Type").Result sValue3 = sValue3 & Chr(44) & Chr(32) sValue4 = .FormFields("Version").Result sValue4 = sValue4 & Chr(44) & Chr(32) sFname = sValue1 & sValue2 _ & sValue3 & "Version " & sValue4 & ".doc" .SaveAs sFname End With End Sub Does that help? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Hello again, If I could trouble you for a question please. I've got the macro running as I previously have said. I've even added an extra Value, and its running great. However all the values are in the tile are only separated by a comma - no space between them. It makes it kinda hard to read. See below C:\Users\Andrew\Documents\D_1234,Cool_QMS,test_doc ument,SOP,V_1.00.doc Is there a way to put a space between each sValue or some other type of charater. I tried " " on the off chance that it might work but got an error. C:\Users\Andrew\Documents\D_1234, Cool_QMS, test_document, SOP, V_1.00.doc You should have said that you were having problems? Glad you got there in the end. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Hi GM, its taken me a while to learn macros to use the code that you gave me a month ago but I just got it to work. its fantastic thanks You are welcome -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: thanks very much You can remove the line MsgBox sFname - that was simply for testing. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Graham Mayor wrote: Assuming your formfields bookmark names are those you indicate, then the following macro run on exit from the last of the relevant fields will save the document in the format you require in the current folder. Alternatively you can add the code to a toolbar save button, Sub FileSaveForm() Dim sValue1 As String Dim sValue2 As String Dim sValue3 As String Dim sValue4 As String Dim sFname As String With ActiveDocument sValue1 = .FormFields("Project_Name").Result sValue2 = .FormFields("Document_Title").Result sValue3 = .FormFields("Document_Type").Result sValue4 = .FormFields("Version").Result sFname = sValue1 & Chr(44) & sValue2 & Chr(44) _ & sValue3 & Chr(44) & "Version " & sValue4 & ".doc" If InStr(1, sFname, " ") 0 Then sFname = Replace(sFname, " ", "_") End If MsgBox sFname .SaveAs sFname End With End Sub http://www.gmayor.com/installing_macro.htm Note the macro does not check whether the filename already exists! Andrew wrote: Hi thanks for persisting with me. The field codes that I am using are from a word 2003 template I made are "text Form Field Codes". I'm currently got word 2007 on my computer. I have inserted the text fields into a table that is on the cover page of the template. Currently the template is stored on my C drive and the documents made from the template are in another folder (although that can change I suppose if it needs too). Hope I have answered your questions with enough detail. cheers Still not enough info. We cannot see your documents! What kind of 'field codes' are these? How are they inserted into the document and how are they stored? -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Andrew wrote: Sorry not enough inf. Im running word 2007 and have created a template. Ive got some feild codes in a template that include the following: Project, version number, title, document category (my own categories for different type of documents used in our company ie SOP, Finished Goods Specification, Record...). Currently staff have to duplicate some information in the file name as well as put it into the cover page of the document. The file name that we use is the sum of the above fields all in a particular order. For example the file name I want people to consistently use is: "Project_Name, Document_Title, Document_Type, Version_#". Is there a way that Word can automate the name of the file based on data entered into the data fields? Thanks Automatically? Fields? Word version? It is certainly possible to save documents with a filename based on information in the document, but you need to tell us something about the document. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Merging a document automatically based on excel or csv data ? | Mailmerge | |||
Stop lines automatically appearing in msword doc. when press ente | Microsoft Word Help | |||
Creating word outline automatically from a text file | Microsoft Word Help | |||
how can I put the file names from a directory into a data base? | Microsoft Word Help | |||
Creating RTF file to be merged with ColdFusion data?? | Mailmerge |