Print Word docs via late binding from Access

K

kiln

Access & Word 2000.

Surprised this isn't totally simple. Using late binding from Access, I
need to print out a set of word docs in succession. During the list
iteration, the following fails with "this command is not available
because there is no document open", error 4248.

Set objWord = CreateObject("Word.Application")

objWord.Documents.Add strPath
objWord.ActiveDocument.PrintOut
objWord.ActiveDocument.Close SaveChanges:=0

I read here that one may printout directly from the application object,
which sounded better anyways, but the following code fails with "this
method or property is not available because a document window is not
active", error 4605.

objWord.PrintOut strPath

I see some API code at

http://www.pacificdb.com.au/MVP/Code/ExeFile.htm

but I'd still like to know how this is done via word automation.

Thanks
 
D

DA

Wouldn't be surprised to find that it's a timing issue.
The Documents.Add probably hasn't completed when the
ActiveDocument.PrintOut is called.

Try a Do Events in between your add and print, and if
that doesn't work, write an error trapping or timing
routine.

Best of luck,
Dennis
 
J

Jezebel

Word often has trouble with the ActiveDocument object. Best avoided in
remote automation. Try it like this:

Set objDoc = objWord.Documents.Add (Template:=strPath)
objDoc.PrintOut
objDoc.Close SaveChanges:=FALSE
set objDoc = Nothing
 
M

Malcolm Smith

For you interest this is exactly what I do when I generate my daily
reports. I have never had a problem with it.

ActiveDocument is really only an internal pointer to Word and I wouldn't
use it at all remotely. After all, one wouldn't need to as one creates
one's own pointer when the document is opened.

I would also check to see that the document is opened and that the file
does exist before opening it.

- Malc
www.dragondrop.com
 
J

Jezebel

Malcolm Smith said:
For you interest this is exactly what I do when I generate my daily
reports. I have never had a problem with it.

Do a Google on it. Several of the VBA sites have a page devoted to
ActiveDocument problems.
 
M

Malcolm Smith

I won't bother as I have enough problems on my hands today.

Actually, it's something similar. One one machine, where I make my
reports it always fails with "Formatting Too Complex" and on other
machines they are fine.

Anyone any ideas?

- Malc
 
M

Malcolm Smith

I won't bother as I have enough problems on my hands today.

Actually, it's something similar. One one machine, where I make my
reports it always fails with "Formatting Too Complex" and on other
machines they are fine.

Anyone any ideas?

- Malc


Problem solved. Upgraded to Office 2003 from 2002 and it worked fine.
Strange error that.
 
K

kiln

OK, thanks. When I try

Set objDoc = objWord.Documents.Add(strPath)

I get error 454 "Object Required". This is all late bound. objWord and
objDoc are both dim'd as Object. Not sure what the error is about.

Also I wonder why the simpler and recommended

objWord.PrintOut strPath

fails...it's not using ActiveDocument at all.
 
J

Jonathan West

Hi kiln

Change this line

objWord.ActiveDocument.PrintOut

to this

objWord.ActiveDocument.PrintOut Background:=false

You can't simply add the path name without naming the argument. But you can
do this

objWord.Printout Background:=False, FileName:=strPath
 
K

kiln

Hi kiln

Change this line

objWord.ActiveDocument.PrintOut

to this

objWord.ActiveDocument.PrintOut Background:=false

You can't simply add the path name without naming the argument. But you can
do this

objWord.Printout Background:=False, FileName:=strPath
OK, thanks
 
K

kiln

objWord.Printout Background:=False, FileName:=strPath

This one is really the ideal as I don't have to open each doc in word
but I still get that failure with "this method or property is not
available because a document window is not active", error 4605.
 
J

Jonathan West

kiln said:
This one is really the ideal as I don't have to open each doc in word
but I still get that failure with "this method or property is not
available because a document window is not active", error 4605.

Then start out with a a blank document open, and close it when you have
printed out all the documents you need.
 
J

Jezebel

I've met that one quite a few times. Work-arounds include clearing the undo
list and saving the document periodically.
 
M

Malcolm Smith

I have a routine which does that and is called all the time. The problem
was solved by installing Word 2003 and removing Word XP.

Now I can use my faster machine to make the daily reports! That saves me
about ten minutes each evening.

- Malc
www.dragondrop.com
 

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