PDA

View Full Version : [SOLVED:] Referencing a template in vba



MacroWizard
11-19-2015, 10:05 AM
I have a template in VBA that has quite a bit of functionality. It has images that are embedded in it as quickparts and a few macros. So the issue is that users will use this template, but when they do a "Save As," they will no longer have access to the images in the template. The problem is that this is a portable document and needs to be usable after a save as. My thoughts are that the code used to reference the template could check to see if the template is the current document. If it is, the template referenced is SELF, if not, the document can reference the template (which will be in the same directory as the document).


Or, possibly even better, if the template isn't the active document, is there a way to allow a user to browse for the template so that the quickparts will work?

Or... if they keep the template open along side the document, is there a way to keep things working from there?

Thanks in advance guys :)

gmaxey
11-19-2015, 04:03 PM
I'm confused. What do you mean when you do a SaveAs? Do you mean that you create a document from your template and then save as a document (.docm) extension file? If so the template is the attached template it loads when the document is loaded.

Paul_Hossler
11-22-2015, 08:14 AM
My 2 cents --

The way I do it is to (might be round about, but I don't do this often enough to try to stream line it)

Create a template with my macros and images and save as a .DOTM file in AppData\Roaming\Microsoft\Templates

Open Word and open the DOTM (hold the shift key down to open the DOTM and not to create a document)

Under QuickParts, Building Blocks Organizer select the image and [Edit Properties...] and change the [Save In] to my template (.DOTM)

Delete the image

Repeat

Save the DOTM

Then using [File] [New] [My Templates] I can just create a new document using the template and the QUickParts and macros are there

Once the DOTM is in the user's AppData, the documents they create are 'portable'.

Only important thing is to save it as a DOCM, but a Before_Close event could probably work there


14821

(in the attachment, just delete the .zip in the name - you can't upload .DOTM for some reason so I had to lie to the software -- it's really a DOTM)