Solved

Word Macro's in templates

Posted on 2006-11-15
3
521 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:roycasella
[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 500 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:roycasella
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

Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
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 teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
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…

733 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