Referencing the current document

H

hals_left

I have a sub in a bas file, called from Document_New() that writes data
to a document.

Is thier a way to reference the document that ensures that you are
working with the document created by the template and not other open /
active documents.

I have been using ActiveDocument but it does not work with other open
documents/instances of word etc.

thanks
hals_left
 
C

Chuck

Create an object pointing to the document. For example if you put

Dim oDoc As Object

Set oDoc = ActiveDocument

in your Document_New sub, you can use oDoc instead of ActiveDocument to
reference the document created in Document_New (in the code above
"ActiveDocument" is the document created by Document_New).
 
A

AndyE

Try checking activedocument.attachedtemplate. That should allow you to see
if the document you are accessing is based on your template or someother.
 
H

hals_left

OK..In Document_New I create the reference & call a userform to get
some data.

Private Sub Document_New()
Dim oDoc As Object
Set oDoc = ActiveDocument
frmQual.Show
End Sub

In the user forms button eevnt I call a sub in Module1 and hide the
user form.

Private Sub cmdOK_Click()
populateDoc txtID.Value
Me.Hide
End Sub

In the sub I want to write to oDoc:

Sub populateDoc ( id )
With oDoc.Tables(1)

But get the error variable not defined.

How can I get it to see oDoc ?
Thanks.
 

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