<DocumentObjetct>.Document_New

D

dmoncayo

Hello all.

Whenever I write vba code in the context of a document, I can use the
"Me" keyword to refer to the Document object in which I am.

However, I've noticed that, in the Document_New method, "Me" sometimes
refers to the document template, and other times it refers to the new
document that is being created (put a breakpoint and check the value
of "Me.FullName").

Does anyone know what is the rule that explain this behavior?
 
C

Cindy M.

Whenever I write vba code in the context of a document, I can use the
"Me" keyword to refer to the Document object in which I am.

However, I've noticed that, in the Document_New method, "Me" sometimes
refers to the document template, and other times it refers to the new
document that is being created (put a breakpoint and check the value
of "Me.FullName").

Does anyone know what is the rule that explain this behavior?
"Me" should refer to the code container (the class). My inclination
would be to not use it at all in the context of a document (it's OK in a
UserForm class, as that's less ambiguous).

Document_New is actually an event, located in the ThisDocument class
module. In the case of a template, I'd expect "Me" to refer to the
template, but if you're seeing otherwise, then I'd call it a bug. My
best guess would be that, when you're seeing this, you're "in a crack"
where the document is still being generated from the template.

What happens if you use ThisDocument in place of "Me" in the event?

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

Dani

Cindy M. said:
"Me" should refer to the code container (the class). My inclination
would be to not use it at all in the context of a document (it's OK in a
UserForm class, as that's less ambiguous).

Document_New is actually an event, located in the ThisDocument class
module. In the case of a template, I'd expect "Me" to refer to the
template, but if you're seeing otherwise, then I'd call it a bug. My
best guess would be that, when you're seeing this, you're "in a crack"
where the document is still being generated from the template.

What happens if you use ThisDocument in place of "Me" in the event?

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


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

Cindy, I appreciate your answer. Thank you.

"ThisDocument" always refers to the template document. I agree with you in
than "Me" should always refer to the object which has the code, that is to
say, the Template Document.

I solved the problem by doing this: At the very begining of the Document_New
method, I store the value of "ActiveDocument" in a global variable, and
thereafter I always use that variable to refer to the final 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