Macro - ActiveDocument

A

Amber

Hello,

We have a macro that we use with our HotDocs program (its a document
automation program). In the macro we call for it to take the ActiveDocument
to protect and save it. Normally this works great but when one of our users
has other word documents open while creating a document in HotDocs the macro
will take one of the users documents that they have open and it will protect
and save it. This leaves our document that came out of HotDocs just sitting
there not protected or saved.

Is there something else that I can call the ActiveDocument or is there some
other way around this?
 
J

Jonathan West

Amber said:
Hello,

We have a macro that we use with our HotDocs program (its a document
automation program). In the macro we call for it to take the
ActiveDocument
to protect and save it. Normally this works great but when one of our
users
has other word documents open while creating a document in HotDocs the
macro
will take one of the users documents that they have open and it will
protect
and save it. This leaves our document that came out of HotDocs just
sitting
there not protected or saved.

Is there something else that I can call the ActiveDocument or is there
some
other way around this?

Yes,, when you first open or create the document with your macro, do
something like this

Dim oDoc As Document
Set oDoc = Documents.Open("C:\test.doc")

Almost certainly, you will need to change that seconds line to math the way
you are actually opening or creating the document, but the key point is that
you assign it to an object variable.

Then, wherever in your macro you were previously referring to
ActiveDocument, refer instead to oDoc.
 
M

Mike

This is a pretty open-ended question ...

The simpliest answer is that if your macro is designed to protect/save the
active document, make sure the user has opened and is positioned on the
document to be protected/saved when they run the macro.

If you are programatically creating or opening the document through VBA code
in the HotDocs program, you can dim an object variable [Dim oDoc as Document]
and then reference that object variable when you add or open the actual
document in code [Set oDoc = Documents.Add ... or Documents.Open] ... (check
the Word help for the exact syntax) ... Your subsequent code to protect and
save the document can use this object variable to indicate which particular
document should be saved/protected.
 
A

Amber

Thanks:)

Mike said:
This is a pretty open-ended question ...

The simpliest answer is that if your macro is designed to protect/save the
active document, make sure the user has opened and is positioned on the
document to be protected/saved when they run the macro.

If you are programatically creating or opening the document through VBA code
in the HotDocs program, you can dim an object variable [Dim oDoc as Document]
and then reference that object variable when you add or open the actual
document in code [Set oDoc = Documents.Add ... or Documents.Open] ... (check
the Word help for the exact syntax) ... Your subsequent code to protect and
save the document can use this object variable to indicate which particular
document should be saved/protected.



Amber said:
Hello,

We have a macro that we use with our HotDocs program (its a document
automation program). In the macro we call for it to take the ActiveDocument
to protect and save it. Normally this works great but when one of our users
has other word documents open while creating a document in HotDocs the macro
will take one of the users documents that they have open and it will protect
and save it. This leaves our document that came out of HotDocs just sitting
there not protected or saved.

Is there something else that I can call the ActiveDocument or is there some
other way around this?
 
A

Amber

Thank you.

Jonathan West said:
Yes,, when you first open or create the document with your macro, do
something like this

Dim oDoc As Document
Set oDoc = Documents.Open("C:\test.doc")

Almost certainly, you will need to change that seconds line to math the way
you are actually opening or creating the document, but the key point is that
you assign it to an object variable.

Then, wherever in your macro you were previously referring to
ActiveDocument, refer instead to oDoc.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
 

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