Print Excel file via VB

K

KitCaz

Recently someone provided some succinct code to print Word documents from VB
code. Can someone provide similar code for printing Excel files?

e.g. Word code:

Dim WordObj As Object
Set WordObj = CreateObject("Word.Application")
WordObj.Documents.Open "c:\yourfile.doc"
WordObj.PrintOut Background:=False, Copies:=1
WordObj.Quit
Set WordObj = Nothing
 
E

Ed

Check the Excel VBE Help for the PrintOut method. Note that it's used on
the Range object. You may also want to read the PrintArea method.

This is Excel VBA code (which is what this newsgroup deals with). But it
will also work in VB6 if you declare an Excel.Application object (like the
Word.Application object in your code); with a reference to the Excel object
model and an Excel object, VB6 code will look almost identical to VBA.
(VB.Net is a different animal that I am not familiar with.)
Ed
 
A

arunkhemlai

I have no vb to test, it works for vb-script; try it yourself.

Dim ExcelApp, ExcelWb

Set ExcelApp = CreateObject("Excel.Application")
Set ExcelWb = ExcelApp.WorkBooks.Open("yourfile.xls")
ExcelWb.WorkSheets.PrintOut
ExcelApp.Quit
Set ExcelObj = Nothing
 
K

KitCaz

Hey, your code snippet worked great. Thank you!

Can you speculate on similar code to print a PowerPoint (.mpp) file? (last
one :)).

Thanks in advance,

Chris
 

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