Home |
Search |
Today's Posts |
#1
|
|||
|
|||
Creating Filename from Form Data
I have created a Doc Template in Word, and I would like to extract data from
Form fields and create a filename. A Macro example I have found do not seem to work, OR I am having difficulty modifying it successfully to extract the data from my form fields. Is there something I am issing? |
#2
|
|||
|
|||
jeffy wrote:
I have created a Doc Template in Word, and I would like to extract data from Form fields and create a filename. A Macro example I have found do not seem to work, OR I am having difficulty modifying it successfully to extract the data from my form fields. Is there something I am issing? There's really no way for us to tell whether you're missing something unless you post the relevant code for us to look at. Also explain exactly what does happen vs. what you expect to happen. Do you get the wrong filename, or no filename, or do you get an error? If there's an error message, quote the message exactly, and tell us which line of code is highlighted in the editor when that happens. Before you go to that trouble, double-check that the field names you use in the code exactly match the spelling of the "bookmark names" in the Properties dialogs of the fields in the form. If you can remember, also tell us where you got the macro example so we can look at that. Finally, this topic would be more appropriate in one of the programming newsgroups such as microsoft.public.word.vba.beginners. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#3
|
|||
|
|||
I have attached the code that I am attempting to use.
When I insert it into my Template, I get a blank filename when I attempt to save. My bookmarks are checjked and double checked. Sub FileSave() With Application.Dialogs(wdDialogFileSaveAs) .Name = Model & " SN" & Serial & " " & RNumber & " " & Customer .Show End With End Sub "Jay Freedman" wrote: jeffy wrote: I have created a Doc Template in Word, and I would like to extract data from Form fields and create a filename. A Macro example I have found do not seem to work, OR I am having difficulty modifying it successfully to extract the data from my form fields. Is there something I am issing? There's really no way for us to tell whether you're missing something unless you post the relevant code for us to look at. Also explain exactly what does happen vs. what you expect to happen. Do you get the wrong filename, or no filename, or do you get an error? If there's an error message, quote the message exactly, and tell us which line of code is highlighted in the editor when that happens. Before you go to that trouble, double-check that the field names you use in the code exactly match the spelling of the "bookmark names" in the Properties dialogs of the fields in the form. If you can remember, also tell us where you got the macro example so we can look at that. Finally, this topic would be more appropriate in one of the programming newsgroups such as microsoft.public.word.vba.beginners. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#4
|
|||
|
|||
Should I assume that Model, Serial, RNumber, and Customer are the names of
the form fields -- what you see in the Bookmark box in the Properties dialogs? VBA looks at those words and assumes that they're VBA variables, not field names. And since you haven't assigned any value to those "variables", they're empty (that's the default value for Variant type variables). Instead, you need to declare the variables in Dim statements and assign the contents of the fields to those variables. It works like this: Sub FileSave() Dim MyModel As String, MySerial As String Dim MyNumber As String, MyCustomer As String MyModel = ActiveDocument.FormFields("Model").Result MySerial = ActiveDocument.FormFields("Serial").Result MyNumber = ActiveDocument.FormFields("RNumber").Result MyCustomer = ActiveDocument.FormFields("Customer").Result With Application.Dialogs(wdDialogFileSaveAs) .Name = MyModel & " SN" & MySerial & " " & _ MyNumber & " " & MyCustomer .Show End With End Sub A properly designed macro would also check that the fields aren't empty, and possibly validate them (for example, to make sure the serial number contains 7 digits and no other characters, or whatever the rules are). -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org jeffy wrote: I have attached the code that I am attempting to use. When I insert it into my Template, I get a blank filename when I attempt to save. My bookmarks are checjked and double checked. Sub FileSave() With Application.Dialogs(wdDialogFileSaveAs) .Name = Model & " SN" & Serial & " " & RNumber & " " & Customer .Show End With End Sub "Jay Freedman" wrote: jeffy wrote: I have created a Doc Template in Word, and I would like to extract data from Form fields and create a filename. A Macro example I have found do not seem to work, OR I am having difficulty modifying it successfully to extract the data from my form fields. Is there something I am issing? There's really no way for us to tell whether you're missing something unless you post the relevant code for us to look at. Also explain exactly what does happen vs. what you expect to happen. Do you get the wrong filename, or no filename, or do you get an error? If there's an error message, quote the message exactly, and tell us which line of code is highlighted in the editor when that happens. Before you go to that trouble, double-check that the field names you use in the code exactly match the spelling of the "bookmark names" in the Properties dialogs of the fields in the form. If you can remember, also tell us where you got the macro example so we can look at that. Finally, this topic would be more appropriate in one of the programming newsgroups such as microsoft.public.word.vba.beginners. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#5
|
|||
|
|||
Your code looks great. I have inserted it as a macro, and double checked all
of the Bookmarks/Variable assignments against my template to be sure they are correct. Now it seems to do the standard First Line of Text filename when I select Save As. I appreciate your patience as I stretch my wings here. Regards, Jeff "Jay Freedman" wrote: Should I assume that Model, Serial, RNumber, and Customer are the names of the form fields -- what you see in the Bookmark box in the Properties dialogs? VBA looks at those words and assumes that they're VBA variables, not field names. And since you haven't assigned any value to those "variables", they're empty (that's the default value for Variant type variables). Instead, you need to declare the variables in Dim statements and assign the contents of the fields to those variables. It works like this: Sub FileSave() Dim MyModel As String, MySerial As String Dim MyNumber As String, MyCustomer As String MyModel = ActiveDocument.FormFields("Model").Result MySerial = ActiveDocument.FormFields("Serial").Result MyNumber = ActiveDocument.FormFields("RNumber").Result MyCustomer = ActiveDocument.FormFields("Customer").Result With Application.Dialogs(wdDialogFileSaveAs) .Name = MyModel & " SN" & MySerial & " " & _ MyNumber & " " & MyCustomer .Show End With End Sub A properly designed macro would also check that the fields aren't empty, and possibly validate them (for example, to make sure the serial number contains 7 digits and no other characters, or whatever the rules are). -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org jeffy wrote: I have attached the code that I am attempting to use. When I insert it into my Template, I get a blank filename when I attempt to save. My bookmarks are checjked and double checked. Sub FileSave() With Application.Dialogs(wdDialogFileSaveAs) .Name = Model & " SN" & Serial & " " & RNumber & " " & Customer .Show End With End Sub "Jay Freedman" wrote: jeffy wrote: I have created a Doc Template in Word, and I would like to extract data from Form fields and create a filename. A Macro example I have found do not seem to work, OR I am having difficulty modifying it successfully to extract the data from my form fields. Is there something I am issing? There's really no way for us to tell whether you're missing something unless you post the relevant code for us to look at. Also explain exactly what does happen vs. what you expect to happen. Do you get the wrong filename, or no filename, or do you get an error? If there's an error message, quote the message exactly, and tell us which line of code is highlighted in the editor when that happens. Before you go to that trouble, double-check that the field names you use in the code exactly match the spelling of the "bookmark names" in the Properties dialogs of the fields in the form. If you can remember, also tell us where you got the macro example so we can look at that. Finally, this topic would be more appropriate in one of the programming newsgroups such as microsoft.public.word.vba.beginners. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#6
|
|||
|
|||
Got it!!! I am using FileSave not FileSaveAs.
Works Great...Thanks again!!! Jeff "jeffy" wrote: Your code looks great. I have inserted it as a macro, and double checked all of the Bookmarks/Variable assignments against my template to be sure they are correct. Now it seems to do the standard First Line of Text filename when I select Save As. I appreciate your patience as I stretch my wings here. Regards, Jeff "Jay Freedman" wrote: Should I assume that Model, Serial, RNumber, and Customer are the names of the form fields -- what you see in the Bookmark box in the Properties dialogs? VBA looks at those words and assumes that they're VBA variables, not field names. And since you haven't assigned any value to those "variables", they're empty (that's the default value for Variant type variables). Instead, you need to declare the variables in Dim statements and assign the contents of the fields to those variables. It works like this: Sub FileSave() Dim MyModel As String, MySerial As String Dim MyNumber As String, MyCustomer As String MyModel = ActiveDocument.FormFields("Model").Result MySerial = ActiveDocument.FormFields("Serial").Result MyNumber = ActiveDocument.FormFields("RNumber").Result MyCustomer = ActiveDocument.FormFields("Customer").Result With Application.Dialogs(wdDialogFileSaveAs) .Name = MyModel & " SN" & MySerial & " " & _ MyNumber & " " & MyCustomer .Show End With End Sub A properly designed macro would also check that the fields aren't empty, and possibly validate them (for example, to make sure the serial number contains 7 digits and no other characters, or whatever the rules are). -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org jeffy wrote: I have attached the code that I am attempting to use. When I insert it into my Template, I get a blank filename when I attempt to save. My bookmarks are checjked and double checked. Sub FileSave() With Application.Dialogs(wdDialogFileSaveAs) .Name = Model & " SN" & Serial & " " & RNumber & " " & Customer .Show End With End Sub "Jay Freedman" wrote: jeffy wrote: I have created a Doc Template in Word, and I would like to extract data from Form fields and create a filename. A Macro example I have found do not seem to work, OR I am having difficulty modifying it successfully to extract the data from my form fields. Is there something I am issing? There's really no way for us to tell whether you're missing something unless you post the relevant code for us to look at. Also explain exactly what does happen vs. what you expect to happen. Do you get the wrong filename, or no filename, or do you get an error? If there's an error message, quote the message exactly, and tell us which line of code is highlighted in the editor when that happens. Before you go to that trouble, double-check that the field names you use in the code exactly match the spelling of the "bookmark names" in the Properties dialogs of the fields in the form. If you can remember, also tell us where you got the macro example so we can look at that. Finally, this topic would be more appropriate in one of the programming newsgroups such as microsoft.public.word.vba.beginners. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
#7
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating Filename from Form Data
can a similar macro be used to create file names from the files' "properties"
data? -- agibson "Jay Freedman" wrote: Should I assume that Model, Serial, RNumber, and Customer are the names of the form fields -- what you see in the Bookmark box in the Properties dialogs? VBA looks at those words and assumes that they're VBA variables, not field names. And since you haven't assigned any value to those "variables", they're empty (that's the default value for Variant type variables). Instead, you need to declare the variables in Dim statements and assign the contents of the fields to those variables. It works like this: Sub FileSave() Dim MyModel As String, MySerial As String Dim MyNumber As String, MyCustomer As String MyModel = ActiveDocument.FormFields("Model").Result MySerial = ActiveDocument.FormFields("Serial").Result MyNumber = ActiveDocument.FormFields("RNumber").Result MyCustomer = ActiveDocument.FormFields("Customer").Result With Application.Dialogs(wdDialogFileSaveAs) .Name = MyModel & " SN" & MySerial & " " & _ MyNumber & " " & MyCustomer .Show End With End Sub A properly designed macro would also check that the fields aren't empty, and possibly validate them (for example, to make sure the serial number contains 7 digits and no other characters, or whatever the rules are). -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org jeffy wrote: I have attached the code that I am attempting to use. When I insert it into my Template, I get a blank filename when I attempt to save. My bookmarks are checjked and double checked. Sub FileSave() With Application.Dialogs(wdDialogFileSaveAs) .Name = Model & " SN" & Serial & " " & RNumber & " " & Customer .Show End With End Sub "Jay Freedman" wrote: jeffy wrote: I have created a Doc Template in Word, and I would like to extract data from Form fields and create a filename. A Macro example I have found do not seem to work, OR I am having difficulty modifying it successfully to extract the data from my form fields. Is there something I am issing? There's really no way for us to tell whether you're missing something unless you post the relevant code for us to look at. Also explain exactly what does happen vs. what you expect to happen. Do you get the wrong filename, or no filename, or do you get an error? If there's an error message, quote the message exactly, and tell us which line of code is highlighted in the editor when that happens. Before you go to that trouble, double-check that the field names you use in the code exactly match the spelling of the "bookmark names" in the Properties dialogs of the fields in the form. If you can remember, also tell us where you got the macro example so we can look at that. Finally, this topic would be more appropriate in one of the programming newsgroups such as microsoft.public.word.vba.beginners. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Creating a data update request form | Microsoft Word Help | |||
Data Form button | Mailmerge | |||
Can you convert regular text in a table into form field data easil | Microsoft Word Help | |||
Same Form letter different Data Base | Microsoft Word Help | |||
Enter data in 1 text form field & have multiple locations fill | Microsoft Word Help |