One Word Template Macro, Two Documents, Problems with Variables

P

Paul J

I have created a Word 2003 template (a business form) containing macros. It
is entirely possible for a User to launch more than one instance of the
template at the same time thus creating Doument1, Document2, etc.

Whereas I want to share (the values of) specific variables between the
macros and functions of a Module, I do not want these values shared between
instances of the macros related to different documents.

The following example illustrates the main problem:

Option Explicit '
Static Sub upTst() ' Assigned to Alt+/
Dim Count As Integer ' Value to be retained between uses
Count = Count + 1 '
StatusBar = Count ' Show us what it is
End Sub '

Pressing Alt+/ on either Document1 or Document2 (created from the Word
template holding the above macro) will display the same incremented value -
not their own version of it.

All offers of advice will be gratefully received.

Paul J
 
C

Cindy M.

Hi Paul,
I have created a Word 2003 template (a business form) containing macros. It
is entirely possible for a User to launch more than one instance of the
template at the same time thus creating Doument1, Document2, etc.

Whereas I want to share (the values of) specific variables between the
macros and functions of a Module, I do not want these values shared between
instances of the macros related to different documents.
The best thing would be to create a CLASS and have each document instantiate
its own instance of the class. This will let you store document-specific
values.
The following example illustrates the main problem:

Option Explicit '
Static Sub upTst() ' Assigned to Alt+/
Dim Count As Integer ' Value to be retained between uses
Count = Count + 1 '
StatusBar = Count ' Show us what it is
End Sub '

Pressing Alt+/ on either Document1 or Document2 (created from the Word
template holding the above macro) will display the same incremented value -
not their own version of it.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
S

Sachya

Hello Paul,
Try storing the count as a property into the document and access it from
there.
It should make sure that you get value with respect to the instance of the
document.

$
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top