Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-23-2022, 09:07 AM
Peterson Peterson is offline Content blocks stop working when changing file path Windows 10 Content blocks stop working when changing file path Office 2019
Competent Performer
 
Join Date: Jan 2017
Posts: 143
Peterson is on a distinguished road
Default

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
Reply With Quote
  #2  
Old 03-23-2022, 01:14 PM
gorkac gorkac is offline Content blocks stop working when changing file path Windows 10 Content blocks stop working when changing file path Office 2019
Banned
Content blocks stop working when changing file path
 
Join Date: Jul 2021
Location: Usa
Posts: 62
gorkac is on a distinguished road
Default

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
Reply With Quote
  #3  
Old 03-23-2022, 02:35 PM
Peterson Peterson is offline Content blocks stop working when changing file path Windows 10 Content blocks stop working when changing file path Office 2019
Competent Performer
 
Join Date: Jan 2017
Posts: 143
Peterson is on a distinguished road
Default

Quote:
Originally Posted by gorkac View Post
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.
Yes, that is how the program is designed to work, as I noted earlier. If you click Open, then Word opens the template file. If you click New, then Word creates a new document based on the template. This is simply how it works, and it cannot be changed, any more than I could, say, change the brake pedal on my car to control acceleration instead of stopping.
Quote:
Originally Posted by gorkac View Post
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
I don't know exactly what you or your users are trying to do. I can't see what you're doing. Your users may be complaining that they want Microsoft's interface to work differently than the way it does -- see my brake pedal analogy.
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.
Reply With Quote
  #4  
Old 03-24-2022, 03:15 AM
gorkac gorkac is offline Content blocks stop working when changing file path Windows 10 Content blocks stop working when changing file path Office 2019
Banned
Content blocks stop working when changing file path
 
Join Date: Jul 2021
Location: Usa
Posts: 62
gorkac is on a distinguished road
Default

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



Similar Threads
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
Content blocks stop working when changing file path New building blocks have stopped working (Word 2016) Genericname1111 Word 0 05-20-2020 04:17 PM
Content blocks stop working when changing file path Get image path from content control field - NO VBA possible 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

Other Forums: Access Forums

All times are GMT -7. The time now is 06:57 AM.


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