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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to print word documents using vba in excel

Status
Not open for further replies.

Mikey0509

Technical User
Mar 2, 2009
5
GB
i have manage to print out word documents using vba in other word documents (ie one document has part numbers, a seperate document has the labels template) using this formula


Application.PrintOut FileName:="", Range:=wdPrintCurrentPage, Outputfilename:="C:\Temp\filename.doc", Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=True, PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0


i now need to print a word document using using vba in excel (managers decided the write the part numbers in excel but keep labels in word)

i have tried using the same formula as above but i keep getting a run time error, do i need to the edit the above formula, if so what bits, or do i need a whole new formula again is so what.

Much appreciated
 
all i have done is add a button via the developer tool, go into the coding page, right in the above code and add the file paths in

when the person clicks on the button the page that the button links to will print this works if the doncuments are both word2007

but when i create this button in excel2007 go to the coding section add the exact same code to print the labels off which are in word2007 it doesnt work
 
You have to use a Word.Application object instantiated with the CreateObject or GetObject functions.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 



Example: Check VBA Help on CreateObject or GetObject.

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
im still really confused on this subject

i would just stick with word to word but its not my decision (damn managers)

i dont understand the create/getobject command the help isnt helping me
:(


is there anything i can add to this code

Code:
Application.PrintOut FileName:="", Range:=wdPrintCurrentPage, Outputfilename:="C:\Temp\filename.doc", Item:= _
        wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
        Collate:=True, Background:=True, PrintToFile:=True, PrintZoomColumn:=0, _
        PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0

or do i need a completly differnt code??
 



Did you read the discussion and see the examples code in the Help that was previously referenced?

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
yes but didnt really understand, think im just gonna persuade them to keep it in word
 
It may be difficult to understand, but here is a hint:

You have:

Application.PrintOut FileName:="",

right? You are running this in/from Excel. So...what is the "Application"?

Excel.

As those instructions are Word instruction, you need to create an instance of Word to use those instructions.

Thus: CreateObject or GetObject. You need to make an instance of Word to use Word. Otherwise, if you are running the code in Excel, "Application" means...Excel.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top