How to save a new word document based on a custom template in a specific folder?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,761
Office Version
  1. 365
Platform
  1. Windows
As far as I know, the are only two ways to create a new document based on a custom template. I can click on File > New in a Word document that is already open. Or I can double click the template itself in the template folder. But either way, when I go to save the document the default folder is OneDrive.

Suppose I want to create several new Word documents, all based on the same custom template, and save them all in a specific folder. Suppose, for example, that I want to send my resume to a number of different possible employers and I want to create cover letters to go with them. Is there any way that I can do something in that folder to create a new Word document based on a specific custom template and have the default save location be that folder?

Thanks

PS: Is this a good place to ask questions about Word? This forum is the gold standard for questions about Excel, and I see it has a section for Access, but not one for Word. If this is not the best place, is there a better place?

PPS: I am running Office 365 on Windows 11
 
When using File > New in Word you don't need to have a document that is already open.

If you add the following code to your template's 'ThisDocument' code module, it will intercept the FileSave dialogue when you first save the file, nominating the template's own folder as the save folder.
VBA Code:
Sub FileSave()
If InStr(ActiveDocument.Name, ".do") > 0 Then ActiveDocument.Save
With Application.Dialogs(wdDialogFileSaveAs)
  .Name = AttachedTemplate.Path
  .Display
End With
End Sub
You can nominate a specific folder if you prefer, using ' .Name' code like
VBA Code:
 .Name = "C:\Users\" & Environ("Username") & "\Documents\Resumes
 
Upvote 0
When using File > New in Word you don't need to have a document that is already open.

If you add the following code to your template's 'ThisDocument' code module, it will intercept the FileSave dialogue when you first save the file, nominating the template's own folder as the save folder.
VBA Code:
Sub FileSave()
If InStr(ActiveDocument.Name, ".do") > 0 Then ActiveDocument.Save
With Application.Dialogs(wdDialogFileSaveAs)
  .Name = AttachedTemplate.Path
  .Display
End With
End Sub
You can nominate a specific folder if you prefer, using ' .Name' code like
VBA Code:
 .Name = "C:\Users\" & Environ("Username") & "\Documents\Resumes

Thanks, Paul, helpful as always.

If I understand this correctly, either I have to put a template in the target folder or I have to modify code in the macro to point to a specific folder. Is that correct?

I would prefer to have all of my templates in the standard custom template folder rather than scattered around in document folders. So that means I would have to modify that code in the macro whenever I want to change the destination folder. Is that correct?
 
Upvote 0
As coded, the macro saves the document to the template's folder, but I also included code showing how you can make it point to another folder.

Obviously, if you want the new documents saved to different folders each time, a file-save macro you have to keep modifying isn't going to be of much use.
 
Upvote 0
I really just wanted a simple straightforward way to be able to create a new document based on a custom template and save it in the folder that I had open. But I guess this was too much to ask for from the geniuses at Microsoft.

Your solution is a good one, but I wanted something a little more general. So I asked ChatGBT. I had no idea what I was getting into. I have spent several hours in each of the last three days working on what I believe is a pretty darn good solution.

I now have a VBA macro that will save a newly created file in a folder of my choice. It does so by reading a “Settings” file (.dotm) in my custom templates folder. In it, I can put one or more folder paths each one prefixed by a code. It will then show me the list of paths and let me choose the one I want for this file. The settings file can also contain blank lines and comment lines to make it more readable.

Here's an example of the contents of a valid Settings file:

* Donation letters
Donate2025 C:\Users\User\Documents\Finances & Investments\Donations\2024
* Resume letters
Resumes C:\Users\User\Documents\Resumes
* Misc
Misc C:\Users\User\Documents

The macro is several pages long and it involves four or five subroutines. It seems to be working, but I haven't done all the testing that I want to do eventually. It is also not documented the way I would like it to be.

I'm posting this To let you all know that I would be happy to post the complete macro here if that's OK with the administrators and if there's any interest.
 
Upvote 0
Assuming you have different templates for your Donations, Resumes, and other documents (viz. Donation.dotm, Resume.dotm, and Normal.dotm), you could use a macro like:
VBA Code:
Sub FileSave()
Dim StrNm As String: StrNm = Split(AttachedTemplate.Name, ".dot")(0)
If InStr(ActiveDocument.Name, ".doc") > 0 Then ActiveDocument.Save
With Application.Dialogs(wdDialogFileSaveAs)
  Select Case StrNm
    Case "Donation": .Name = "C:\Users\" & Environ("Username") & "\Documents\Finances & Investments\Donations"
    Case "Resume": .Name = "C:\Users\" & Environ("Username") & "\Documents\Resumes"
    Case Else: .Name = "C:\Users\" & Environ("Username") & "\Documents"
  .Display
End With
End Sub
 
Upvote 0
Assuming you have different templates for your Donations, Resumes, and other documents (viz. Donation.dotm, Resume.dotm, and Normal.dotm), you could use a macro like:
VBA Code:
Sub FileSave()
Dim StrNm As String: StrNm = Split(AttachedTemplate.Name, ".dot")(0)
If InStr(ActiveDocument.Name, ".doc") > 0 Then ActiveDocument.Save
With Application.Dialogs(wdDialogFileSaveAs)
  Select Case StrNm
    Case "Donation": .Name = "C:\Users\" & Environ("Username") & "\Documents\Finances & Investments\Donations"
    Case "Resume": .Name = "C:\Users\" & Environ("Username") & "\Documents\Resumes"
    Case Else: .Name = "C:\Users\" & Environ("Username") & "\Documents"
  .Display
End With
End Sub
But that still requires that the templates be in those folders, correct?

I would prefer to have all of my custom templates in the same custom template folder rather than scattered around the disk for a couple of reasons. First, I would know where they are. Second, I might need the same template for more than one folder and that would mean more than one copy which would mean a royal pain in the *** to keep them in sync.
 
Upvote 0
The templates can be in whatever folder you like. What determines the default save location is the template's name, not where it is stored.
 
Upvote 0
The templates can be in whatever folder you like. What determines the default save location is the template's name, not where it is stored.

I see. The macro checks the name of the template in your Select Case block and then determines the Save-in folder using the folder name that is hard coded in the macro. Is that correct?

One problem I see with that approach is that files that are created using the "Donation" template, for example, can only be stored in the folder whose name is coded in that Case statement. Correct?

Our “SmartSave” macro can save any file created by any template in any folder that is listed in the Settings file. I simply have to execute File > New and then select the template. When the document opens, I simply click on the SmartSave icon that I put in the Quick Access Toolbar. That will run the macro which will load the list of destination folders from the Settings file and let me choose the one that I want.

So my templates can all be in the same custom template folder along with the Settings file, but they are not exclusively connected to any one folder.

And I have a few enhancements that I want to work on when I get a few minutes. One of them would be to allow me to copy and paste the destination folder into the InputBox at the macro puts up to let me choose one of the destination folders in the Settings file. That would allow me to designate any folder any time. Another is to then have the macro add that folder to the Settings file.
 
Upvote 0
Yes, the default location is set via the Select Case code block. But that's only the default. If the user wants to save to another folder, they can simply navigate to it via the SaveAs dialogue box - or the user could input it via copy/paste. So, for example, I didn't include the donation year folder in the default save path for donations. When the donations folder opens, the user can simply click on the relevant year to open the year folder. This should be helpful when transitioning from one year to another.
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top