Consulting

Results 1 to 3 of 3

Thread: Referencing a template in vba

  1. #1

    Referencing a template in vba

    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

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    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.
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    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


    Capture.JPG

    (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)
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •