Open and Process w/o Seeing Document

B

BillCPA

I would like to open several documents and do some processing on them without
actually seeing the documents.

I open a 'Main' document which runs 'Macro A' which displays a user form.
Macro A then proceeds to open several documents and does some processing on
each one, then closes that document. The user form has a text box that
displays the name of the document that is being worked on. But when each
document is opened, it throws up the window in whch the document is opened.

I tried setting the 'Visible' parameter in the .Open to False, but then the
ActiveDocument remains the Main document and it tries to do the processing on
the Main document.

There is probably a simple solution to this, but it eludes me at the moment.
 
J

Jonathan West

BillCPA said:
I would like to open several documents and do some processing on them
without
actually seeing the documents.

I open a 'Main' document which runs 'Macro A' which displays a user form.
Macro A then proceeds to open several documents and does some processing
on
each one, then closes that document. The user form has a text box that
displays the name of the document that is being worked on. But when each
document is opened, it throws up the window in whch the document is
opened.

I tried setting the 'Visible' parameter in the .Open to False, but then
the
ActiveDocument remains the Main document and it tries to do the processing
on
the Main document.

There is probably a simple solution to this, but it eludes me at the
moment.

There is. Don't use ActiveDocument. Instead, do this

Dim oDoc as Document
Set oDoc = Documents.Open(Filename:=sFullname, Visible:=False)

In the sample above, sFullname is the full pathname of the file you want to
open. Once you have the document open like this, process it exactly as you
do now, except that wherever you currently use ActiveDocument, use oDoc
instead, and you mustn't use Selection at all.
 
G

Graham Mayor

Dim sDoc As Document
Application.ScreenUpdating = False
Set sDoc = Documents.Open(FileName:="C:\Path\Filename.doc", _
Visible:=False)
sDoc.Activate
'**************
'Do your stuff here
'**************
sDoc.Close SaveChanges:=wdSaveChanges
Application.ScreenUpdating = True

should take you closer to what you are trying to achieve.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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