Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Print Excel file via VB

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Print Excel file via VB

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

"KitCaz" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Print Excel file via VB

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



"KitCaz" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Print Excel file via VB

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

"arunkhemlai" wrote:

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



"KitCaz" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
print all worksheets of Excel file to one pdf file Centerfield Excel Discussion (Misc queries) 3 April 30th 09 04:51 AM
my excel is converting all my print jobs to print to file why? Ginger Excel Discussion (Misc queries) 2 April 10th 07 12:28 PM
How do I print from a file created from sending a print to a file Ted Johnston Excel Discussion (Misc queries) 1 February 23rd 06 03:10 AM
Print to File: In Excel? pk Excel Programming 1 October 17th 03 02:13 PM
FILE Save As / FILE Print greyed out in Excel Jeff Wright Excel Programming 2 September 3rd 03 09:29 AM


All times are GMT +1. The time now is 05:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"