![]() |
|
#1
|
|||
|
|||
![]()
Right-clicking and selecting Open is how Microsoft designed Word to open template files so that you can work in them and not create a blank document based on them. There is no way to right-click on a template, select Open, and have it create a new blank document based on the template.
Your users are not using Word to create blank documents in the way Microsoft designed the program to work. The primary method of creating a new file based on a template is via File > New. In the screen that appears, there is a Personal button. When users click Personal, Word displays all of the templates in the user's default template storage folder. The user should then click on the template with which they want to create a new document. The other way to create a new file from a template is, as you noted, to double-click on a template that's already in a folder somewhere. But, again, it is not possible to right-click on a template, select Open, and create a document based on that template. To create a new file based on a template using VBA, use the following: Code:
Sub CreateNewDocFromUserTemplate() ' 03/23/2022 ' Create a variable for the filepath to your template: Dim strFilepath As String ' Use the Environ("UserProfile") function to get the first portion of the ' user's file path -- that is, C:\User\username -- and concatenate with the ' rest of the path to the template in your users' template folder: strFilepath = Environ("UserProfile") & _ "\AppData\Roaming\Microsoft\Templates\Replace-This-With-Your-Template.dotm" ' Here's what the full string looks like: Debug.Print strFilepath ' Create new document based on template: Documents.Add (strFilepath) End Sub |
#2
|
|||
|
|||
![]()
But when I right click on the template, the context menu shows Open, New, Print, Save as...etc. The New option opens a document based on the template, however the Open option opens the entire template.
Captura1.PNG On the other hand, I have programmed a button on the ribbon to save in the appropriate format, based on the template, but none of the options work for me. And that the Document1 document that is opened is in docx format Code:
Sub Docm(control As IRibbonControl) With Dialogs(wdDialogFileSaveAs) .Format = wdFormatXMLDocumentMacroEnabled .Show End With End Sub |
#3
|
|||
|
|||
![]() Quote:
Quote:
It sounds like you need to open the actual template file, then save a copy of it as a docm file. You may need to write or find code that will open the template, then you can use your sub above to save it as a docm file, then close the template. Perhaps another member of this forum can help you with that, if needed. |
#4
|
|||
|
|||
![]()
What I need is that they always open a new document based on the template. Prevent the template from working.
At the moment it has occurred to me, from Document_Open, to launch a message asking them to close the template and reopen it as "New". For them to work the document based on the template. It is that if they work the template directly, someone will spoil it. Code:
Sub Document_Open() 'macro message MsgBox "CLOSE TEMPLATE, PLEASE REOPEN " _ & "DOUBLE LEFT-CLICK ON THE TEMPLATE OR, WITH THE RIGHT MOUSE BUTTON, SELECT ''NEW''" End Sub |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Mapped Content Controls in Building Blocks? | Charles Kenyon | Word | 6 | 05-21-2021 05:40 PM |
Stop hyperlink to a file from changing address - causes problems with pdf | c.davidson | Word | 1 | 09-15-2020 11:11 PM |
![]() |
Genericname1111 | Word | 0 | 05-20-2020 04:17 PM |
![]() |
thoerzer | Word | 5 | 10-10-2019 12:10 AM |
Changing Absolute path to Relative in a Macro | MrKim | Excel Programming | 13 | 01-26-2019 02:18 PM |