application.printout fails

R

red6000

Hi,

I have code which prints a file using:

Application.PrintOut FileName:="C:\test.doc"

The code works fine, but only if a document is open at the time (it can be
any document).

I've amended the code to be:

Documents.Open Filename:= "C:\tempfile.doc"
Application.PrintOut FileName:="C:\test.doc"
Documents("tempfile.doc").Close wdSaveChanges = False

The actual file to be printed is a variable based on data entered into a
userform. Why does word need any random document open in order for the code
to work and is there a neater way to 'trick' it?

Thanks.
 
J

Jean-Guy Marcil

red6000 was telling us:
red6000 nous racontait que :
Hi,

I have code which prints a file using:

Application.PrintOut FileName:="C:\test.doc"

The code works fine, but only if a document is open at the time (it
can be any document).

I've amended the code to be:

Documents.Open Filename:= "C:\tempfile.doc"
Application.PrintOut FileName:="C:\test.doc"
Documents("tempfile.doc").Close wdSaveChanges = False

The actual file to be printed is a variable based on data entered
into a userform. Why does word need any random document open in
order for the code to work and is there a neater way to 'trick' it?

Thanks.

Use something like:

With Application
If .Documents.Count = 0 Then
.Documents.Add
End If
.PrintOut FileName:="C:\test.doc"
End With

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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