Printing a Word document from Excel spreadsheet

R

ringo tan

Hi,

I would like to check whether how to control open, print and close a Word
document say, 'quotation.doc' from Excel.

I need to perform this operation because I have to do my detailed
calculations in Excel in order to derive at a final quotation price,
afterwhich dump this price on a Word template (quotation.doc) and print the
quotation out.

Thank you.



Ringo Tan
 
S

Sharad Naik

In excel first add reference to "Mocrosoft Word xx.x Object Library"
Then:-

Sub WdocPrinter()
Dim appWD As Word.Application, myPath As String
myPath = "C:\My Documents" 'Set the path for your quotation.doc file
Set appWD = CreateObject("Word.Application")
appWD.Documents.Open Filename:=myPath & "\quotation.doc"
With appWD.ActiveDocument
.PrintOut
.Close
End With
End Sub

Sharad
 
R

ringo tan

Hi Sharad,

Thank you for your kind help but i dont know how to add the reference
"Microsoft Word xx.x Object Library" in Excel?

Thank you
 
S

Sharad Naik

In a Visual Basic Editor, click on Tools menu and select references.
References window appears.
Scroll down and find 'Microsoft Word 11.0 Object Library'' (depending upon
your version it might not be 11.0, something else, hence I put xx.x.)
Check the box fot that library and click on OK.

Sharad
 
D

Dave Peterson

Another option that maybe be safer (you won't have to worry about different
versions of word):

Just change this line:
Dim appWD As Word.Application, myPath As String
to
Dim appWD As Object, myPath As String

This is called late binding. Excel will figure out what you want from the
createobject() line.

When you do this: "Dim appWD As Word.Application", it's called early
binding--you're telling excel that you'll handle the details.

Early binding is nice for development (and it's slightly quicker
(unnoticeable???), but with late binding you don't have to worry about
supporting multiple versions of office.

(and it's an easy change!)
 
S

Sharad Naik

Thanks Dave :)
Dave Peterson said:
Another option that maybe be safer (you won't have to worry about
different
versions of word):

Just change this line:
Dim appWD As Word.Application, myPath As String
to
Dim appWD As Object, myPath As String

This is called late binding. Excel will figure out what you want from the
createobject() line.

When you do this: "Dim appWD As Word.Application", it's called early
binding--you're telling excel that you'll handle the details.

Early binding is nice for development (and it's slightly quicker
(unnoticeable???), but with late binding you don't have to worry about
supporting multiple versions of office.

(and it's an easy change!)
 

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