Link to home
Start Free TrialLog in
Avatar of ROM
ROMFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Word Macro's in templates

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
Avatar of cquinn
cquinn
Flag of United Kingdom of Great Britain and Northern Ireland image

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
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ROM

ASKER

cquinn... didnt work im afraid

grahamskan..

yep..worked a treat

many thanks

Romolo