Definition of 'ThisDocument'

E

elle0612

Hi

Can anyone define what object the 'ThisDocument' is in the VBA editor screen?

In my case - my Word 2000 vba project is a template so is the 'ThisDocument'
object mentioned, the page that fronts the template and belongs with the
template?

If I am correct in my guess, can you open and close 'ThisDocument' as your
ActiveDocument, just like opening a document from another file to include it
as part of your project?

If correct what code would open and close 'ThisDocument' as ActiveDocument?

If I am wrong on all counts, just a simple definition of what 'ThisDocument'
is would suffice.

Thanks
 
J

Jean-Guy Marcil

elle0612 was telling us:
elle0612 nous racontait que :
Hi

Can anyone define what object the 'ThisDocument' is in the VBA editor
screen?

In my case - my Word 2000 vba project is a template so is the
'ThisDocument' object mentioned, the page that fronts the template
and belongs with the template?

If I am correct in my guess, can you open and close 'ThisDocument' as
your ActiveDocument, just like opening a document from another file
to include it as part of your project?

If correct what code would open and close 'ThisDocument' as
ActiveDocument?

If I am wrong on all counts, just a simple definition of what
'ThisDocument' is would suffice.

ThisDocument is a class module that refers to the code container,

So, for example, let's say you have code in a template (*.dot) that
manipulates Document Variables.
Now you create a document based on that template.
Suppose you have this code :

ActiveDocument.Variable("Test").Value = "MyName"
ThisDocument.Variable("Test").Value = "MyName"

The first line will update (or create it if it does not exist) a variable
called Test in the currently active document (or the document created from
the template that contains the code).
The second line will update the variable in the template itself, not the
document.

So, when you use ThisDocument in the code, you are referring to the code
container, usually the template used to create the currently active
document.

Since a template is not really "opened" when you create a document, you
cannot open/close it in the normal sense. It is available because it is
attached to a document and is loaded. If you modify it (as in my example
above) you will have to save the changes unless you want them discarded.
You could actually open it is well, but this is very rarely necessary.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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