Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2006

Tip: Looking for answers? Try searching our database.

Determining if the template is attached.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jan Kucera - 21 Sep 2006 14:41 GMT
Hi Cindy, hi all!
Using vbscript, I open a document and a template as a document which I
attach to it using myOpenedDoc.AttachedTemplate = app.Documents.Open(..).

Now, as Cindy explained to me,
I do need to have some way to explicitly UNLOAD (close) the template.
Especially if this is NOT 2003. In earlier versions this was the source of
some really bad memory leaks and other problems.

> However
> how can I find when to close it if this is necessary?

Well... this code I'm placing in the template:

Private Sub Document_Close()
If ThisDocument = ActiveDocument Then Exit Sub

Dim doc As Document
For Each doc In Documents
 If doc.AttachedTemplate = ThisDocument Then Exit Sub
Next doc
ThisDocument.Close False
End Sub

Is this the right way?

Thanks,
    Jan
Jan Kucera - 21 Sep 2006 16:14 GMT
Okay there is a bug because the document being closed is also included in
the collection, but otherwise it seems to work quite ....hey wait i minute,
the template is being attached to itself as well?? :-)

> Hi Cindy, hi all!
> Using vbscript, I open a document and a template as a document which I
[quoted text clipped - 24 lines]
> Thanks,
>     Jan
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.