This lets me successfully open the document but I need some help with figuring out how to output to this. Dim oWord as Object Set oWord CreateObject ('Word.Application') 'C:document.doc' oWord.visible true. Whenever the macro is executed, the attached template for the current document is set to the proper template, and the macros in that template will then be accessible. Before going to the next line in the document, I want to output the string that Ive built into a word document. You can even assign the macro to the Quick Access Toolbar or give it a shortcut key. Make sure the macro is in the Normal template, and you will be all set.
You'll want to make sure that the Target_Template constant is set to the full path to the template you want to use the same one used by the contractors out in the field. This can be very simple, such as this:Ĭonst Target_Template As String = "C:\PathToTemplate\MyTemplate.dotm"ĪctiveDocument.AttachedTemplate = Target_Template If you find yourself needing to do this quite often, you might consider creating a macro on the home-office computers to do the reattachment for you. Reattach the template by following the steps in the tip entitled Changing the Attached Template. It is, no doubt, in a different location on your system than it is on those in the field. You should have, at your office, the same template that is being used by your contractors in the field. All you need to do is when you open the document, reattach the template. Sub GenerateWordDocumentfromExcelMacro() Set WordObject CreateObject('Word.Application') Set DocObject Set SelectionObject WordObject.Selection WordObject.Visible True 16 'Times New Roman' SelectionObject. Knowing this is how Word works with macros in the template leads to a solution, though. the bit after Sub and before () here UpdateAll - (no spaces in the name) box. When it doesn't find it, that means the template isn't available and the macros, therefore, cannot be accessed. When you first open this dialog, and assuming that you have no add-ins installed, and there are no macros in the current document, the dialog will be empty as shown below: Type the Name of the macro into the Macro Name i.e.
The rub comes in when you transfer the document to another computer, such as a computer "back at the office." When you open the document, Word checks for the attached template at the indicated path as stored with the document. select view CCS TeX Code and check the Show the XML only box, copy the XML and paste into your Word document in the following location (Mac).
Thus, there is no need for the document to contain the macros since they are already available through the template. Since the macros are in the template and the template is attached to the document, any macros in the template are available to the document whenever it is open. When you create a document based on a template, Word shows that template as "attached" to the document.
Neil wonders how to get the macros to "travel" with the document created from the template so he can continue to utilize the macros when the document is sent by the contractor to his office. When his contractors create a new document based on the template, the macros stay in the template. Neil has created a template that includes many macros used in the development of a report based on the template.