Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-16-2022, 08:00 AM
Cosmo Cosmo is offline Removing CustomUI when saving word file from template Windows Vista Removing CustomUI when saving word file from template Office 2007
Competent Performer
Removing CustomUI when saving word file from template
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default Removing CustomUI when saving word file from template

I have a template I am creating with a CustomUI ribbon. I have done this in the past, but now the documents created from the template I am working on still have the ribbon elements in the saved document when it is reopened (they don't show up when the document is first created).

The template is a macro enabled template (.dotm), and it is stored in a trusted location (startup folder). I have other templates in the same location that work properly.

I'm at my wit's end with this, my company wants to start using this early next week, and I have spent over a day trying to figure out why this isn't working like the other templates.There are differences, but the basics are the same as the other templates I have used.

This is the code to create the Document:
Application.Documents.Add(Template:=ThisDocument.F ullName, visible:=True)

This is the code used to save the document:
Call Application.ActiveDocument.SaveAs(FileName:=saveFi lePath, FileFormat:=wdFormatXMLDocument)

This is exactly the same code I used for the other documents i have createin the past.

I need this to work on both a Mac and a PC. I have found code that strips the customUI folder from the zip file on a PC, but that was giving me problems as well as it won't be cross-platform.

Can anyone help me, any hint on what I might be missing here?



Edit: For some reason, the forum is adding spaces into the code. The code is correct in the file
Reply With Quote
  #2  
Old 09-16-2022, 09:05 AM
Charles Kenyon Charles Kenyon is offline Removing CustomUI when saving word file from template Windows 11 Removing CustomUI when saving word file from template Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
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

Place your Custom UI in a Global Template rather than in the Document template. It will be there when you produce your document on your system and will not be there when the document is used on another system.
You are using Documents.Add with a template base, correct?

If the CustomUI is specific to each template, then still place it in a separate template and load the template with the CustomUI as an Add-In when you are producing the document. Once you save the document, unload the Add-In.

There is no good reason I can imagine to be placing a CustomUI in a template for documents when you do not want it to be in the document. IMO you are doing things the hard way.


The whole idea of putting customizations in templates is to have them be in the documents produced from the templates.

Templates in Microsoft Word


Reply With Quote
  #3  
Old 09-16-2022, 10:08 AM
Cosmo Cosmo is offline Removing CustomUI when saving word file from template Windows Vista Removing CustomUI when saving word file from template Office 2007
Competent Performer
Removing CustomUI when saving word file from template
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
Place your Custom UI in a Global Template rather than in the Document template. It will be there when you produce your document on your system and will not be there when the document is used on another system.
You are using Documents.Add with a template base, correct?

If the CustomUI is specific to each template, then still place it in a separate template and load the template with the CustomUI as an Add-In when you are producing the document. Once you save the document, unload the Add-In.

There is no good reason I can imagine to be placing a CustomUI in a template for documents when you do not want it to be in the document. IMO you are doing things the hard way.


The whole idea of putting customizations in templates is to have them be in the documents produced from the templates.

Templates in Microsoft Word


Thanks for the response.

I'll look into that, but I don't understand why this has worked for me with multiple documents before? This seems like it will complicate things a bit, if I now have to provide 2 documents for our users to install, and make sure that both are in place, if I understand what you are suggesting. And I will need to get the proper file path to the correct file in the global template, since I can't just reference the template containing the content itself.
Reply With Quote
  #4  
Old 09-16-2022, 12:23 PM
Charles Kenyon Charles Kenyon is offline Removing CustomUI when saving word file from template Windows 11 Removing CustomUI when saving word file from template Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
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

Quote:
Originally Posted by Cosmo View Post
Thanks for the response.

I'll look into that, but I don't understand why this has worked for me with multiple documents before? This seems like it will complicate things a bit, if I now have to provide 2 documents for our users to install, and make sure that both are in place, if I understand what you are suggesting. And I will need to get the proper file path to the correct file in the global template, since I can't just reference the template containing the content itself.
Are your users using your custom UI or just the resulting document?
They are creating documents to go to someone else using your Custom UI?

If in code, you refer to ThisDocument instead of ActiveDocument it gives reference to the file holding the code.

Global templates go in the Word Startup Folder. I can give you code to identify this folder if you need it.
? Application.StartupPath in the Immediate Window identifies it.


Here is a macro
Code:
Sub ShowStartUpPath()
  ' Macro written by Charles Kenyon 2014-02-25
  ' Shows setting for Startup Folder location in Microsoft Word in a message box.
  '
  MsgBox _
    Prompt:="Your StartUp folder location is " & _ 
      Application.StartupPath & _
      "." & Chr(13) & Chr(10) & Chr(13) & Chr(10) & ".", _
      Buttons:=vbOKOnly, _
      Title:="Current Startup Folder Setting Information"
   '
End Sub
Reply With Quote
  #5  
Old 09-16-2022, 12:31 PM
Charles Kenyon Charles Kenyon is offline Removing CustomUI when saving word file from template Windows 11 Removing CustomUI when saving word file from template Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
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

Quote:
Originally Posted by Cosmo View Post
***

I'll look into that, but I don't understand why this has worked for me with multiple documents before?

You are the homeowner coming to the carpenter saying "I've used this hammer to drive screws for the last ten years but it isn't working now."

I do not know why it worked for you in the past and is not working now. I know you are using the wrong tool for the job.
Reply With Quote
  #6  
Old 09-16-2022, 02:09 PM
Cosmo Cosmo is offline Removing CustomUI when saving word file from template Windows Vista Removing CustomUI when saving word file from template Office 2007
Competent Performer
Removing CustomUI when saving word file from template
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
Are your users using your custom UI or just the resulting document?
They are creating documents to go to someone else using your Custom UI?
Mostly, they are using internal documents that can be sent across our company.

Quote:
Originally Posted by Charles Kenyon View Post
If in code, you refer to ThisDocument instead of ActiveDocument it gives reference to the file holding the code.
Yes, that's what I'm using in the 'Add' command, as mentioned in my original posting.

Quote:
Originally Posted by Charles Kenyon View Post
Global templates go in the Word Startup Folder. I can give you code to identify this folder if you need it.
[
That's where I have them loaded already. I have a template that I created a year ago that creates new documents without the customUI, as well as the one I'm working on now that does.

Perhaps I misunderstood what you meant by 'global template'. I was reading that as a separate template file with the UI and VBA code, and a separate template file with the content with no UI and VBA code. Currently, the template file has the content and the UI and VBA. It is stored in the 'Startup Folder' as mentioned in my original posting.

Quote:
Originally Posted by Charles Kenyon View Post
FONT=verdana,arial,helvetica]? Application.StartupPath in the Immediate Window identifies it.[/FONT]


Here is a macro
Code:
Sub ShowStartUpPath()
  ' Macro written by Charles Kenyon 2014-02-25
  ' Shows setting for Startup Folder location in Microsoft Word in a message box.
  '
  MsgBox _
    Prompt:="Your StartUp folder location is " & _ 
      Application.StartupPath & _
      "." & Chr(13) & Chr(10) & Chr(13) & Chr(10) & ".", _
      Buttons:=vbOKOnly, _
      Title:="Current Startup Folder Setting Information"
   '
End Sub
Reply With Quote
  #7  
Old 09-16-2022, 02:55 PM
Charles Kenyon Charles Kenyon is offline Removing CustomUI when saving word file from template Windows 11 Removing CustomUI when saving word file from template Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
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

Quote:
Originally Posted by Cosmo View Post
***

Perhaps I misunderstood what you meant by 'global template'. I was reading that as a separate template file with the UI and VBA code, and a separate template file with the content with no UI and VBA code. Currently, the template file has the content and the UI and VBA.
This is what I mean.
A global template that contains the UI modifications and any related code, separate from the document template that contains the content and document format/styles.
The global could also hold building blocks that can be used to create content.
I am assuming that your UI modification is done by editing the XML of the template, not through vba on-the-fly editing. (Customize the Office Ribbon (It doesn't take rocket science) by Greg Maxey )

A global template in the Startup folder shares the UI modifications with all other documents / templates but does not insert those mods in others. They can be used.
If this is only to work with certain document templates, those templates could load the Add-In upon creation of a document and then the document template's code could unload the Add-In when the new document is closed.
Reply With Quote
  #8  
Old 09-16-2022, 04:07 PM
Cosmo Cosmo is offline Removing CustomUI when saving word file from template Windows Vista Removing CustomUI when saving word file from template Office 2007
Competent Performer
Removing CustomUI when saving word file from template
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
This is what I mean.
A global template that contains the UI modifications and any related code, separate from the document template that contains the content and document format/styles.
The global could also hold building blocks that can be used to create content.
I am assuming that your UI modification is done by editing the XML of the template, not through vba on-the-fly editing. (Customize the Office Ribbon (It doesn't take rocket science) by Greg Maxey )

A global template in the Startup folder shares the UI modifications with all other documents / templates but does not insert those mods in others. They can be used.
If this is only to work with certain document templates, those templates could load the Add-In upon creation of a document and then the document template's code could unload the Add-In when the new document is closed.
Yes, the UI is done by editing the XML

Ok, so what you're saying is if i have 5 different document templates, I create the templates without code or the CustomUI, and another template with all of the code and CustomUI for all 5 documents?

Currently, i am using the 'Document_New()' event of the template (in the 'ThisDocument' Microsoft Word Objects space) to run the code to set up the document (shows a userform to collect data, and populates the document).

To move the code to a 'Master' template, I'd need to move this activation to an app event handler "App_NewDocument(ByVal Doc As Document)" event in the Master template, then I'd need to determine which template created the active document, and run the setup function(s) needed for that specific template?

Is this the proper workflow?

Edit: after thinking about this, i might be able to keep all of the code for the setup of the document in the content template, and move the rest of the UI specific code to a separate 'Master' since that's mostly for editing/updating the document once it's created. Theres's a 'New XXXX Document' button to create a new document from the specific template, but that would just need to create the document, and the rest of the code would work as usual.

I very much appreciate your assistance, and patience, with me.
Reply With Quote
  #9  
Old 09-16-2022, 08:29 PM
Charles Kenyon Charles Kenyon is offline Removing CustomUI when saving word file from template Windows 11 Removing CustomUI when saving word file from template Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
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

Code related to the UI, if any, should be in the global template. Code related to a particular template should be in the template.

It may be that you have common code triggered by UI elements. If you need a different userform for each template, you put it in the document templates. If you could use the same userform, you put it in the global. If the individual userforms all have the same name, they could be called or triggered by a button on the Ribbon or QAT stored in your global with the context of the active document. Your Document_New procedure could be in the global but trigger a userform in the document template.

You can have keyboard shortcuts in your document templates. You can have them in your document templates.
You could have document variables in your templates that are tested by code in your global template and which change the behavior of code in your global template.

I load 20+ global templates upon startup. Seven or eight of these make changes in the UI. When I work on new documents, those UI changes are available. When I send the document to someone else, the UI changes are not there on their computer, but the document is. I do not have to remove the UI changes from the document; they were never in the document because they were not in the document template. Some, but not all, document templates have code in them.

That I do it this way does not mean it is the only way. I think it is the most conceptually elegant method. The only UI change I might include in a document template would be a QAT button for a built-in Word feature otherwise not obvious and which would be of use in the document (like the Sort command).
Reply With Quote
  #10  
Old 09-17-2022, 12:43 AM
Italophile Italophile is online now Removing CustomUI when saving word file from template Windows 11 Removing CustomUI when saving word file from template Office 2021
Expert
 
Join Date: Mar 2022
Posts: 315
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

It has always been the case that when a document is created from a template it inherits the content of the template except:
  • VBA code
  • ribbon xml
  • building blocks
Those items stay in the template and will be available to the document whilst it remains attached to the template.

I rarely build templates that contain customized ribbon code but occasionally it has been necessary. In the interests of science I just created a document from an old template I created for a client that was using Wd2010. I then compared that to an example document I created from the same template back in 2016. To my surprise the new document contained the ribbon xml whilst the old document didn't.

As I am now using O365 I can only conclude that in Microsoft's infinite wisdom they decided to change how this works at some point. Either that or they've introduced a bug.
Reply With Quote
  #11  
Old 09-17-2022, 09:02 AM
Cosmo Cosmo is offline Removing CustomUI when saving word file from template Windows Vista Removing CustomUI when saving word file from template Office 2007
Competent Performer
Removing CustomUI when saving word file from template
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

Quote:
Originally Posted by Italophile View Post
It has always been the case that when a document is created from a template it inherits the content of the template except:
  • VBA code
  • ribbon xml
  • building blocks
Those items stay in the template and will be available to the document whilst it remains attached to the template.

I rarely build templates that contain customized ribbon code but occasionally it has been necessary. In the interests of science I just created a document from an old template I created for a client that was using Wd2010. I then compared that to an example document I created from the same template back in 2016. To my surprise the new document contained the ribbon xml whilst the old document didn't.

As I am now using O365 I can only conclude that in Microsoft's infinite wisdom they decided to change how this works at some point. Either that or they've introduced a bug.
Ok. So, I'm NOT going crazy. Everything I had read indicated that saving a document from a template would strip out the UI elements, and what you are saying tracks with what I have experienced.

I believe I have a working solution for now, might not be the best but it seems to work to get a usable template for next week. I can update the procedure at a later date if necessary.

When I finish my working template with all code and CustomUI elements, I will make a duplicate of that UI file, strip out the CustomUI elements. The 'Doc-Template.dotm' file will be added to the 'Templates' folder, the 'Doc-Template-UI.dotm' and an alias to the 'Doc-Template.dotm' file will be added to the 'Startup' folder. I have adjusted the code to create a new document from the UI to search the Application.Templates for the correct template file instead of using 'ThisDocument' so that it will use the non-UI template. This allows me to maintain a single template that has all elements necessary for that specific document.

This does mean that there are 2 templates with identical code, but that's not an issue to me. The only issue would be if i need to submit an update to the template, and someone updates one but not the other. This shouldn't be a problem for PC users, as I will be creating an installer to handle that, but for now, i will need Mac users to update the files manually. I will need to look into a similar process for Mac.

Thanks for the assistance, I will look more into the Templates discussion Charles linked to earlier when I have more time to dedicate.
Reply With Quote
  #12  
Old 09-17-2022, 12:33 PM
Charles Kenyon Charles Kenyon is offline Removing CustomUI when saving word file from template Windows 11 Removing CustomUI when saving word file from template Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
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

Quote:
Originally Posted by Italophile View Post
It has always been the case that when a document is created from a template it inherits the content of the template except:
  • VBA code
  • ribbon xml
  • building blocks
Those items stay in the template and will be available to the document whilst it remains attached to the template.

I rarely build templates that contain customized ribbon code but occasionally it has been necessary. In the interests of science I just created a document from an old template I created for a client that was using Wd2010. I then compared that to an example document I created from the same template back in 2016. To my surprise the new document contained the ribbon xml whilst the old document didn't.

As I am now using O365 I can only conclude that in Microsoft's infinite wisdom they decided to change how this works at some point. Either that or they've introduced a bug.
Thank you. I was mistaken.

I am also using 365 and upon creating a document based on one of my global templates that has XML ribbon modifications, those disappear when I attach the document to my normal template. So long as the template remains the attached template, they are present and active. The same is true of QAT modifications saved in the template. I just examined the xml in the .docx file and it did not have the custom xml from the template.

I started Ribbon modification in Word 2010 and just tried this in Word 2010 and had the same results.

I guess it makes sense because many UI modifications require code and that code will not be in the document.


I still feel that UI modification should primarily be in global templates.
Reply With Quote
  #13  
Old 09-17-2022, 07:50 PM
Guessed's Avatar
Guessed Guessed is offline Removing CustomUI when saving word file from template Windows 10 Removing CustomUI when saving word file from template Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

My experience with CustomUI ribbons and templates has been to always put the code (vba and customUI) into the 'attached' template because that is where the applicability matches and there is rarely a reason to complicate the system by implementing partner addins to match the 'attached' template.

However I have seen particular users create documents from templates which accidently get a copy of the CustomUI embedded in the docx file. This happens when their workflow is to OPEN the template and then do a SaveAs to turn it into a docx file. In this special case the CustomUI xml is included in the docx file although any macros would be stripped out as they save unless they choose docm as the format.

I have not yet seen a template with embedded customUI code produce new documents with contained customUI when the documents are created the RIGHT way (File>New or double clicking a dotm file). It is possible that this functionality has been broken on a recent update of Word 365 but I still haven't seen it.

I do wonder why you would put the source new document template in your startup folder instead of the more usual User/Workgroup templates folder. This might be interfering with the code you say you are using
Code:
Application.Documents.Add(Template:=ThisDocument.FullName, visible:=True)
Is that creating an unsaved DocumentX file or is it opening the template itself which you then SaveAs? Opening the template would cause the CustomUI to be replicated in the resulting file.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #14  
Old 09-18-2022, 01:34 AM
Italophile Italophile is online now Removing CustomUI when saving word file from template Windows 11 Removing CustomUI when saving word file from template Office 2021
Expert
 
Join Date: Mar 2022
Posts: 315
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Quote:
Originally Posted by Guessed View Post
I have not yet seen a template with embedded customUI code produce new documents with contained customUI when the documents are created the RIGHT way (File>New or double clicking a dotm file). It is possible that this functionality has been broken on a recent update of Word 365 but I still haven't seen it.
For my testing I placed the template in my user templates folder and created the document using File>New.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving Notes View into Word Template caz46 PowerPoint 0 06-24-2015 01:29 AM
Removing digitally signing when saving plasma Word 0 05-26-2015 08:36 AM
Saving a template file dreamz Word VBA 10 06-26-2014 04:38 AM
Removing CustomUI when saving word file from template Looking for best way to remove VBA and CustomUI from a file via VBA Cosmo Word VBA 1 04-25-2014 06:19 PM
Update Document Template when Saving the Document File bjbercaw Word 3 11-16-2010 02:03 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:16 AM.


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