Code to get UserForm's parent?

E

Ed

I need to be able to put the address - folder location and file name - of
the template containing a UserForm into a string on the Initialize event.
Apparently, though, there isn't a Parent property available (in Word 2000).
How might I do this?

Ed
 
J

Jean-Guy Marcil

Ed was telling us:
Ed nous racontait que :
I need to be able to put the address - folder location and file name
- of the template containing a UserForm into a string on the
Initialize event. Apparently, though, there isn't a Parent property
available (in Word 2000). How might I do this?

Have you tried:

ActiveDocument.AttachedTemplate.FullPath

?

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

Ed

Hi, Jean-Guy. I didn't want to use anything with the ActiveDocument, more
out of ignorance than any other good reason. This would be a UserForm and
code distributed in a separate template as an AddIn. When called and used,
the ActiveDocument would not be associated with the same template as the
UserForm. Would your code still work in this case?

Ed
 
J

Jean-Guy Marcil

Ed was telling us:
Ed nous racontait que :
Hi, Jean-Guy. I didn't want to use anything with the ActiveDocument,
more out of ignorance than any other good reason. This would be a
UserForm and code distributed in a separate template as an AddIn.
When called and used, the ActiveDocument would not be associated with
the same template as the UserForm. Would your code still work in
this case?
Ha! I see.

Then better try as Tony suggests.(ThisDocument.FullName)

BTW, I made a mistake, I meant
ActiveDocument.AttachedTemplate.FullName
and not
ActiveDocument.AttachedTemplate.FullPath

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

Ed

Ah! I saw "ThisDocument" and my mind read "ActiveDocument". So from within
the UserForm, "ThisDocument" will refer to the doc holding the form, even if
it's a template different from the ActiveDocument's template?

Ed
 
E

Ed

I saw "ThisDocument" and my mind read "ActiveDocument". So from within the
UserForm, "ThisDocument" will refer to the doc holding the form, even if
it's a template different from the ActiveDocument's template?

Ed
 
J

Jonathan West

Ed said:
I saw "ThisDocument" and my mind read "ActiveDocument". So from within the
UserForm, "ThisDocument" will refer to the doc holding the form, even if
it's a template different from the ActiveDocument's template?


Correct. You can also use Application.MacroContainer.FullName, which
achieves much the same thing.



--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
T

Tony Jollans

Actually Application.MacroContainer is better - ThisDocument, as I said, is
not guaranteed to work..
 
J

Jonathan West

Tony Jollans said:
Actually Application.MacroContainer is better - ThisDocument, as I said,
is
not guaranteed to work..

I've not come across a case where Application.MacroContainer works and
ThisDocument doesn't. However, they don't behave identically, and this needs
to be known.

ThisDocument is always a Document object. Application.MacroContainer can be
a Document or a Template object according to circumstance. Since Documents
and Templates have a different range of properties, this can trip up the
unwary.

In this case, it doesn't matter all that much, because both Document and
Template objects have a FullName property.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
T

Tony Jollans

It's not that ThisDocument doesn't return the same result - it's just that
"ThisDocument" is a name and not an absolute reference to anything - and it
can be changed (even at runtime).
 
J

Jonathan West

Tony Jollans said:
It's not that ThisDocument doesn't return the same result - it's just that
"ThisDocument" is a name and not an absolute reference to anything - and
it
can be changed (even at runtime).

Ah, I see what you mean. I can't think of a good reason why anyone would
want to change the name of it, but I see that it is possible.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.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