No Access to Template's Document - vba

I have an existing Macro Enabled Template which I would like to add Content Control to, to be available on the screen when the Template is accessed.
I know how to add the Content to a Word Document and then save it as a Template. The problem is that I cannot view the Exisiting Template's Word Document due to the view Object being greyed out. See below:
I really do not want to copy all my Macros and my quick texts over to a new document just to add one line of text and a button.
I can easily add the required text and CommandButton by having a script run in a Document_New Sub under the ThisDocument. The problem is that this Sub bombs out due to Macros not being enabled. I intend to have the Template distributed to numerous colleagues, therefore having the Text and button on the document will avoid any confusion as to what to do with the template.

You need to open the Template via File - Open
Opening the Template this way will display give you access to the Template.
For info: The name of the Template will appear in the Center of the Word Application.

Related

Load macros from dotm

The scenario:
When word starts, it connects via vba to a Service, which returns a list of paths. Each of These paths points to a .dotm file. These files contain information about various controls (inside the ribbon, for example a butto which adds a specific footer).
What I want: I need a possibility to load several .dotm files, but without copying or moving them to a specific location.
Basically that's it. I've searched wide and far and I have the fear, that this Approach is actually not possible, and that I have to copy all dotm files inside the startup-folder and let word do the rest
Is there any way how I can load several dotm files into a single word-file, so that the ribbon gets extended depending on the dotm's
Best regards, please and thanks :)
From word documentation:
This example attaches the template "Letter.dot" to the active document.
ActiveDocument.AttachedTemplate = "C:\Templates\Letter.dot"
You can use this to attach all your templates to the document.
See also the Templates collection.
you can add a template to the Templates collection by using the Add method with the Addins collection to load a global template
Sub AddTemplate()
' For this example to work correctly, verify that the
' path is correct and the file exists.
AddIns.Add FileName:="C:\Program Files\Microsoft Office" _
& "\Templates\Letters & Faxes\MyFax.dot", Install:=True
End Sub
It's not possible to load multiple templates to a single Word file. Only one template can be attached to a document.
It is possible to load multiple templates as add-ins in the Word environment. These will be available then to all documents opened in the Word application. Use the Addins-Add method to add a template to the list in Document/Document Template, the "Global templates and add-ins" list. (This is the equivalent of the "Add" button in the dialog box.)
Dim bInstalled as Boolean
Dim Path as String
Dim fileName as String
'Populate the variables, then...
Application.Addins.Add Filename:=Path & fileName, Install:=bInstalled
Set bInstalled to false if you want the template in the list, but not loaded (Ribbon isn't displayed, for example); set it to true to also load it. Once a template is in the list, whether loaded or unloaded, it will generally remain in the list unless Word is reset in some manner. The code for managing template add-ins would be more efficient if it first checks whether an Add-in is already in the list before adding it again.
Templates that are in the list can be loaded/unloaded using the Addins.Installed property. If the tools in a template should be available only to certain documents then they can be loaded/unloaded dynamically by using events, such as DocumentChange.
The code to load the add-ins and manage them (events) should probably be in a central template in Word's Startup folder or in the template attached directly to the document.

Word Macro to add predefined content at the end of document on click of button

I have an document in word, which has some fields to be filled, and an button to which I want to assign a macro. When that button is clicked, that same form with empty fields needs to be appended to the end of document, including the button (which can be clicked again and do the same thing).
Here is the document I have:
https://drive.google.com/file/d/0B_2kyqxMx5x4UkxfOHJhOGVPdnc/view?usp=sharing
The main problem with what you want to do is dynamically linking the button to the macro code to be executed. The most obvious type of button to use is the legacy ActiveX control in the Ribbon's Developer tab. But that requires its own procedure entry in the document's ThisDocument class module. While it's possible to add code to modules "on the fly" this involves disabling a security option.
A more straignt forward approach is to use the MacroButton field. This creates a clickable text within the document. It can display text or a graphic (so that it looks like a button) and is assigned the name of any public Sub that takes no parameters:
{ MACROBUTTON NameOfMacro Click here }
Ctrl+F9 to insert the field code brackets; Alt+F9 to toggle between field code and field result.
Graphics in Word 2010 and later:* The was a change to the graphics engine in Word 2010 which affects the behavior of graphics objects in the MacroButton field. Clicking the object triggers the Ribbon utility for working with graphics - the field code no longer "hides" the graphic. There are a number of ways you can work around this:
Use an IncludePicture field (which works with the old graphics format) to bring in an outside picture file. Once the linked picture is in the field it can be converted to a static picture by selecting the IncludePicture field and pressing Ctrl+Shift+F9. Word respects the old graphic format and the picture is click-able.
{ MacroButton NameOfMacro {IncludePicture "C:\\Path\\picture.jpg" } }
Use the old *.doc file format. Note that this will restrict some of the things that can be done with the document, but it will force use of the old graphics engine.
Instead of a MacroButton field, use the WindowBeforeDoubleClick event or WindowSelectionChange event to run the code.
*With the exception of unlinking the IncludePicture field (which I discovered myself), this information came from this discussion on the Microsoft Answers site
If you want to run the macro with a single rather than a double-click (the default) you need to run the following line of code. This applies to the entire Word application and needs to be run everytime Word restarts. You could put it in an AutoNew macro in the template / AutoOpen macro in the document:
Application.Options.ButtonFieldClicks = 1
The simplest way to store the entire content you want to insert repeatedly is as a Building Block (formerly known as AutoText).
BuildingBlocks are stored in templates. If your document is being created from a template, that would be the logical place. Another possibility would be a special template you use for this purpose. Normal.dotm can also be used but keep in mind this does sometimes get removed.
(Note: if you're using a template for the document that would also be the best place to store the macro attached to the macro button.)
Once this is set up, all your code needs to do is insert the BuidlingBlock at the end of the document.

Make a ribbon button reference the macro in a new workbook instance rather than in the source template

I have a macro-enabled Excel template which contains a ribbon button pointing to a macro sub. The button assignment still points to the source template, however, instead of the sub in the new document. If I create a document and then move or delete the template, I'm no longer able to use the button in the new document:
I've noticed that the ribbon button seems have the macro's source template path hard-coded, and there isn't any place I can find in ribbon customization UI to change it:
I'm certain this has been asked before, but I've tried a number of different ways of searching for it without coming up with anything.
I found this which talks about a button on a form, not a ribbon, and I found this which seems to be generating "shapes" programmatically and assigning their action; neither of these two are relevant.
This is the closest I've found, but whereas the QAT customization tab has the option for setting the target:
the ribbon customization tab does not have that. Any help would be greatly appreciated.

Exclude template reference and macros from document

I am creating a template which has some macros inside. What the macros do is to open a user form which will prompt the user for some information which will then go into the new document.
The problem is that once the new document is created, it still somehow have a reference to this template and the macro code.
I have to send the document to people outside of the organization and they get a warning that the document contains macros.
Is there a way to avoid this? I want the document to be created without any of the macros or referrence to the original template.
Try creating the new document with "Normal" as a parameter for the Documents.Add method. The default seems to be to create a document off of the current open template (or Normal if none).

Can I base a word template on another template

For the purposes of branding, our Word normal.dot template is updated via the login script. This pains me terribly, because I have a number of very useful VBA macros that I want to have access to. Specifically, I have two macros that I add to the Quick Access Toolbar in the title bar that I use all the time.
From what I understand, those macros can only be taken from the document itself or from the template it is based on.
What I am looking for, is a way to either:
Add a QAT button to a macro in another file somewhere.
Base all my documents on a new template (call it abnormal.dot) which in turn is based on normal.dot, so it can retain the macros even when normal.dot is overwritten.
Any other way of achieving my goal.
Any ideas?
You can add additional templates to your Word Application.
Go to Developer Tab on the Ribbon >> Templates section >> press Document Templates...
In new window on Template page you will find Add button on the right- add there some additional templates. This should help.