View Single Post
 
Old 09-16-2022, 08:29 PM
Charles Kenyon Charles Kenyon is offline Windows 11 Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,472
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