#1
|
|||
|
|||
Save File with specific name from fields input.
Hi,
I have a template created in Word 2013. It asks for certain fields to be input by using “FILLIN”. Input is required for Name, Address, City, and Invoice No. The input fields are defined and setup using ALT F9. How can I use the above inputted fields to save the file? It currently defaults to the file name that the templates is name. I would like the file to be saved as Invoice No – Name Any assistance would be appreciated. Thanks |
#2
|
|||
|
|||
This will require a macro. If you are willing to use one, let me know. See Instructions for Installing Macros from Forums or Websites by Graham Mayor, MVP
Fill-In fields are old technology. They are very stable, but they tend to annoy users when used sequentially. Why not use Content Controls instead? They are also very stable. Word Content Controls by Greg Maxey |
#3
|
|||
|
|||
I am quite happy to use macros.
I am totally new to this so please be gentle. You also suggest that FILLIN is old hard and something else is available, quite happy to do this, please point me to where I can learn from to change. Thanks |
#4
|
|||
|
|||
I did give you a link about Content Controls. Here is another: Create forms that users fill out.
You can also use them to repeat data throughout a document. Repeating Data Using Document Properties Content Controls and Other Mapped Content Controls I will assume that you will be using Content Controls and will post a macro. |
#5
|
|||
|
|||
The key language in the following macro is:
Code:
strName = strName & " " & ActiveDocument.ContentControls(1).Range.Text 'add name from first content control Here is a pair of macros that I use: Code:
Sub FileSaveAs() ' Run as substitute for FileSave to add date to default document names ' Charles Kenyon 2017, 2019, 2020 ' Appends date to Title Document property when saving On Error Resume Next If Len(ActiveDocument.Path) > 0 Then ' The document has already been saved at least once. ' Just save and exit the macro. ActiveDocument.Save Exit Sub End If ' ' Dim strName As String, dlgSave As Dialog Dim strPath As String 'Holder for current path Let strPath = Application.Options.DefaultFilePath(wdDocumentsPath) Set dlgSave = Dialogs(wdDialogFileSaveAs) strName = ActiveDocument.BuiltInDocumentProperties("Title").Value 'get name in title strName = strName & " " & ActiveDocument.ContentControls(1).Range.Text 'add name from first content control strName = strName & " " & Format((Year(Now() + 1) Mod 100), "20##") & "-" & _ Format((Month(Now() + 1) Mod 100), "0#") & "-" & _ Format((Day(Now()) Mod 100), "0#") 'add date With dlgSave .Name = strPath & strName .Show End With ' Reset save path Let Application.Options.DefaultFilePath(wdDocumentsPath) = strPath ' empty object Set dlgSave = Nothing End Sub Sub FileSave() FileSaveAs End Sub This grabs the Title from document properties and adds the content of the first content control in the document and then the date. |
#6
|
|||
|
|||
Charles,
Firstly, thanks for offering to assist. I have read the information you have send and revieweed it. Unfortunately, due to time constraints, it is not pratical to change the way the template has been set up to use Content Control. Is it still possible to use what I currently have to pass the appropriate fields to a macro to save the files to the same place that the template is store in? If so further assitance would be appreciated. I do not have any programming experience and therefore be gentle. Thanks |
#7
|
|||
|
|||
While I think on this, it having been a while since I've used FillIn fields, here is a link to my tutorial on using these fields, which will not answer your question.
Ask & Fill-In Field Tutorial How are you going to identify the field to vba? Is it the only Fill-In Field in the document? Is it bookmarked in some way, as it would be automatically with an ASK field? |
#8
|
|||
|
|||
Interim step:
The following code gets the result from the first Fill-In field in a document and assigns it to the variable strResult. Code:
Sub FieldResultFillIn() ' Charles Kenyon 30 Sept. 2020 Dim strResult As String Dim oField As Field On Error GoTo ErrorHandler For Each oField In ActiveDocument.Fields If oField.Type = wdFieldFillIn Then Let strResult = oField.Result Exit For End If Next oField If strResult = "" Then MsgBox "No Fill-In Fields in this document." Else MsgBox "The text in the first Fill-In field in the document is:" & vbCrLf & strResult End If GoTo Cleanup ErrorHandler: MsgBox "There do not appear to be any fields in this document." Cleanup: Set oField = Nothing On Error GoTo -1 End Sub |
#9
|
|||
|
|||
Quote:
Name, address, Town, ZIP,.Invoice to name a few. I am away from work now so will have a look at your recommendations tomorrow. Would it be advantageous to change FILLIN to ASK as ASK creates bookmarks and these can be used to create the name of the file to be saved? (I.e invoice-Name). |
#10
|
|||
|
|||
It would be advantageous, yes. Then we could simply look for the bookmarks.
Look at the Ask & Fill-In Field Tutorial because Ask Fields act a bit differently than Fill-In Fields. Which would you want in the file name? I will assume bookmarks named: Invoice and Name. You should look into creating a UserForm to gather the information and use it. A UserForm is a custom dialog box that can gather information and choices and then use that appropriately in a document. These could also use Bookmarks. |
#11
|
|||
|
|||
With Bookmarks named "Invoice" and "Name" in your document and the following macros in the document's template you should get what you want.
Code:
Sub FileSaveAs() ' Run as substitute for FileSave to add bookmark contents to default document names ' Charles Kenyon 2017, 2019, 2020 ' Appends date to Title Document property when saving On Error Resume Next If Len(ActiveDocument.Path) > 0 Then ' The document has already been saved at least once. ' Just save and exit the macro. ActiveDocument.Save Exit Sub End If ' On Error GoTo BookMarkMissing ' Dim strName As String, dlgSave As Dialog Dim strPath As String 'Holder for current path Let strPath = Application.Options.DefaultFilePath(wdDocumentsPath) Set dlgSave = Dialogs(wdDialogFileSaveAs) Let strName = ActiveDocument.Bookmarks("Invoice").Range.Text & " - " & _ ActiveDocument.Bookmarks("Name").Range.Text ' Let strName = strName & " " & Format((Year(Now() + 1) Mod 100), "20##") & "-" & _ Format((Month(Now() + 1) Mod 100), "0#") & "-" & _ Format((Day(Now()) Mod 100), "0#") 'add date With dlgSave Let .Name = strPath & "\" & strName .Show End With ' Reset save path GoTo ResumeProcess BookMarkMissing: MsgBox "It appears that one or more of the bookmarks Name or Invoice is missing." ResumeProcess: Let Application.Options.DefaultFilePath(wdDocumentsPath) = strPath ' empty object and reset Error Handler Set dlgSave = Nothing On Error GoTo -1 End Sub Sub FileSave() FileSaveAs End Sub Last edited by Charles Kenyon; 10-01-2020 at 08:59 AM. |
#12
|
|||
|
|||
Charles,
I have reviewed the information you have sent so far, and I thank you for this. Unfortunately, due to time constraints, the Creation of User Forms is a “no no”, as people do not have time to do it, and it will lead to training issues, time that the small company doesn’t have. I have been told just to change the existing template to see if saving new documents can be standardised automatically (currently, people manually type in file name and don't always follow the nameing conventions). Can I not just change the FILL-IN in the current template to ASK and store the answer as bookmarks to subsequently go into the macro? That will take the least time and that is the way they want to go, as they have several other templates that require file naming to be standardised. So if there is any other way to achieve what I want? Regards Last edited by Charles Kenyon; 10-01-2020 at 09:00 AM. |
#13
|
|||
|
|||
The code I posted last night works with two bookmarks. You can change the template in one of two ways:
|
#14
|
|||
|
|||
Two reasons I do not like sequential Ask and Fill-In fields:
|
#15
|
|||
|
|||
Charles,
Unfortunately I am getting nowhere with this. In the following lines of code there are {} which have been typed in for completness. In the actual code they have been generated by using the CTRL + F9 keys Previously, I had, FILLIN {"Customer Full Name" \* MERGEFORMAT } this used to ask me for input. Now I have changed the line to read {ASK CustName "Customer Full Name" \* MERGEFORMAT} and it doesn’t ask me to enter data. I then changed the above to, {ASK CustName "Customer Full Name" \* MERGEFORMAT} followed by {REF CustName \h} This again does not ask for input and hence I get Error! Reference source not found. What am I doing wrong? I want the data to be input for Customer and Invoice No. Please help. Last edited by PM1; 10-03-2020 at 03:49 AM. Reason: errors |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Creating a template with repeat of fields and user input | jhansrod | Word VBA | 0 | 06-13-2019 08:03 AM |
Linking Specific text fields in PP to specific cells in an Excel table | GWRW1964 | PowerPoint | 0 | 02-26-2018 07:37 AM |
How do I update all fields from a new input | Kozzzle | Word | 7 | 10-19-2017 06:12 PM |
Help with Macro to Save Word File as PDF in Specific Location | ekimisme | Word VBA | 1 | 06-07-2017 10:40 PM |
Save Excel file with specific cell value by using VBA code | IAMCHEESE | Excel Programming | 1 | 11-02-2016 07:11 PM |