Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-29-2020, 03:21 AM
PM1 PM1 is offline Save File with specific name from fields input. Windows 10 Save File with specific name from fields input. Office 2013
Novice
Save File with specific name from fields input.
 
Join Date: Sep 2020
Posts: 8
PM1 is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 09-29-2020, 07:16 AM
Charles Kenyon Charles Kenyon is offline Save File with specific name from fields input. Windows 10 Save File with specific name from fields input. Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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
Reply With Quote
  #3  
Old 09-29-2020, 07:35 AM
PM1 PM1 is offline Save File with specific name from fields input. Windows 10 Save File with specific name from fields input. Office 2013
Novice
Save File with specific name from fields input.
 
Join Date: Sep 2020
Posts: 8
PM1 is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 09-29-2020, 08:56 AM
Charles Kenyon Charles Kenyon is offline Save File with specific name from fields input. Windows 10 Save File with specific name from fields input. Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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.
Reply With Quote
  #5  
Old 09-29-2020, 09:11 AM
Charles Kenyon Charles Kenyon is offline Save File with specific name from fields input. Windows 10 Save File with specific name from fields input. Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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.
Reply With Quote
  #6  
Old 09-30-2020, 06:22 AM
PM1 PM1 is offline Save File with specific name from fields input. Windows 10 Save File with specific name from fields input. Office 2013
Novice
Save File with specific name from fields input.
 
Join Date: Sep 2020
Posts: 8
PM1 is on a distinguished road
Default

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
Reply With Quote
  #7  
Old 09-30-2020, 07:08 AM
Charles Kenyon Charles Kenyon is offline Save File with specific name from fields input. Windows 10 Save File with specific name from fields input. Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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?
Reply With Quote
  #8  
Old 09-30-2020, 07:27 AM
Charles Kenyon Charles Kenyon is offline Save File with specific name from fields input. Windows 10 Save File with specific name from fields input. Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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
To put this together, though, I need the questions asked previously answered.
Reply With Quote
  #9  
Old 09-30-2020, 07:38 AM
PM1 PM1 is offline Save File with specific name from fields input. Windows 10 Save File with specific name from fields input. Office 2013
Novice
Save File with specific name from fields input.
 
Join Date: Sep 2020
Posts: 8
PM1 is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
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?
There are a few FILL-IN fields.

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).
Reply With Quote
  #10  
Old 09-30-2020, 11:40 AM
Charles Kenyon Charles Kenyon is offline Save File with specific name from fields input. Windows 10 Save File with specific name from fields input. Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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.
Reply With Quote
  #11  
Old 09-30-2020, 07:27 PM
Charles Kenyon Charles Kenyon is offline Save File with specific name from fields input. Windows 10 Save File with specific name from fields input. Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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.
Reply With Quote
  #12  
Old 10-01-2020, 06:42 AM
PM1 PM1 is offline Save File with specific name from fields input. Windows 10 Save File with specific name from fields input. Office 2013
Novice
Save File with specific name from fields input.
 
Join Date: Sep 2020
Posts: 8
PM1 is on a distinguished road
Default

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.
Reply With Quote
  #13  
Old 10-01-2020, 08:44 AM
Charles Kenyon Charles Kenyon is offline Save File with specific name from fields input. Windows 10 Save File with specific name from fields input. Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

The code I posted last night works with two bookmarks. You can change the template in one of two ways:
  • Add bookmarks around your Fill-In fields, or
  • Change to ASK fields and add a REF field cross-referenced to the bookmarks where your current Fill-In Fields are. An ASK field creates a bookmark with the response but does not, itself, display the response. The response to an ASK field is saved invisible, inside a bookmark, unless called upon by a cross-reference. I again refer you to my tutorial.
Reply With Quote
  #14  
Old 10-01-2020, 08:57 AM
Charles Kenyon Charles Kenyon is offline Save File with specific name from fields input. Windows 10 Save File with specific name from fields input. Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Two reasons I do not like sequential Ask and Fill-In fields:
  • They are annoying. If you type an answer wrong, you can't back up and do over.
  • If you have the option to update fields upon printing, you may be asked the questions again when you print and different answers will change what is in the document.
UserForm advantages
  • You can see everything you need to input at once.
  • Some choices can depend on other input.
  • You can fix mistakes easily.
  • It only runs when you want it to.
  • You can put information in bookmarks, document properties, or document variables for later retrieval or use. (You could put in content controls as well.)
  • - Disadvantage: User must allow macros to run, but you need macros to do what you want anyway. Also requires some programming skill to set up, although not a lot.
Content Control Advantages:
I realize that you are not in control of the situation, but you are doing things the hard way. There is nothing wrong with Fill-In fields, in and of themselves.
Reply With Quote
  #15  
Old 10-02-2020, 06:26 AM
PM1 PM1 is offline Save File with specific name from fields input. Windows 10 Save File with specific name from fields input. Office 2013
Novice
Save File with specific name from fields input.
 
Join Date: Sep 2020
Posts: 8
PM1 is on a distinguished road
Default

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
Reply With Quote
Reply

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
Save File with specific name from fields input. 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

Other Forums: Access Forums

All times are GMT -7. The time now is 06:37 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft