Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Word Macro's in templates

Posted on 2006-11-15
3
Medium Priority
?
525 Views
Last Modified: 2010-08-05
Word Macro's in templates

Currently we have code that works perfectly when opening the document up.  The sub procedure "AutoOpen()" placed in the "ThisDocument" module of the Word Objects part of the project runs and will open a userform.  That userform, then uses the ThisDocument command to change the picture of an image control within the document called "imgSpace", using the following code:

ThisDocument.imgSpace.Picture = LoadPicture(ImagePath)

This all works fine....that is until the document is then converted to a template.  When it is a template, it creates a copy of itself (with references to the original template code), the autoopen() procedure will not run and the references to ThisDocument.imgSpace no longer work.

How can i convert the code to automatically run when the template is opened...and only this template (so not global), and also refer to the control "imgSpace" within the new document based on the template.

Hope this all makes sense, and thank you in advance.

Many thanks

Romolo
0
Comment
Question by:Romolo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Expert Comment

by:cquinn
ID: 17945748
Go into the VBA editor (Alt+F11)  in the template, then Insert/Module from the menu, right click on the module and rename it to AutoOpen, then insert a proceduer called

Public Sub MAIN()
    'Your code goes here
End Sub
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 17945974
Microsoft is trying to move away from the Auto.. macros. In the case of AutoOpen, you can use the Document_New and Document_Open events in the ThisDocument module of your template.

When you create a new document from the template, ThisDocument refers to the template itself. ActiveDocument will refer to the new document.

 
0
 
LVL 7

Author Comment

by:Romolo
ID: 17946111
cquinn... didnt work im afraid

grahamskan..

yep..worked a treat

many thanks

Romolo
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question