Determining if the template is attached.

J

Jan Kucera

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
 
J

Jan Kucera

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

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