Re: One Word Template Macro, Two Documents, Problems with Variables

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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 :-)

.



Relevant Pages

  • Re: double-click hyperlinks
    ... so long as they click the button to enable macros when the document is ... if the macro is in the template and the template is in the ... This message is posted to a newsgroup. ... > hyperlinks has been ...
    (microsoft.public.word.vba.userforms)
  • Re: Save as Template and loss macros
    ... "Charles Kenyon" escreveu: ... This changes your template name and/or location. ... This message is posted to a newsgroup. ... template and keep it with the same name and type and macros. ...
    (microsoft.public.word.vba.general)
  • Re: Template Save Changes (Word 2000)
    ... You can have your macros save them at that time. ... This message is posted to a newsgroup. ... assignments that are saved in the template. ... These all install Add-Ins that mess with your ...
    (microsoft.public.word.vba.general)
  • Re: Save as Template and loss macros
    ... template and keep it with the same name and type and macros. ... Microsoft's Legal Users' Guide) http://addbalance.com/usersguide ... This message is posted to a newsgroup. ...
    (microsoft.public.word.vba.general)
  • Re: Moving Macros between computers in Word 2003
    ... It is possible that your user stored the macros in some other template. ... Microsoft's Legal Users' Guide) http://addbalance.com/usersguide ... This message is posted to a newsgroup. ...
    (microsoft.public.word.docmanagement)