Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing documents from VB

Status
Not open for further replies.

oconv

Programmer
Jan 17, 2002
25
ZA
How can you print Word Documents from VB ???

I tried :::

Dim MSWord As Object
Set MSWord = GetObject("C:\My Documents\Test.doc")
MSWord.application.PrintOut


but I get a error that the method/property is not available because the document window is not active.


Is there anyway to accomplish this without actually opening the word document??

Thanks
 
Try this:

Dim wrd As Word.Application
Dim doc As Word.Document

Set wrd = CreateObject("Word.Application")
wrd.Visible = False
Set doc = wrd.Documents.Open("C:\My Documents\Test.doc")
doc.PrintOut True
Do While wrd.BackgroundPrintingStatus <> 0
Loop
doc.Close
wrd.Quit
Set doc = Nothing
Set wrd = Nothing
 
You need to extend your code:

[tt]Dim MSWord As Object, WordDoc As Object
Set MSWord = GetObject(&quot;Word.Application&quot;)
Set WordDoc=MSWord.Documents.Open FileName:=&quot;C:\My Documents\Test.doc&quot;
With WordDoc
.PrintOut
.Close SaveChanges:=wdDoNotSaveChanges
End With
MSWord.Quit[/tt]

and set objects to Nothing.

combo


 
If you simply want to print the document, you might want to consider using the ShellExecute API using &quot;print&quot; as the operation (2nd parameter)
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top