Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 273
Default OLE or Automation Printing of Excel

I need a way to setting up excel to "print to fit" fom MS Access using
Automation or OLE. The VBA code below allows to print the excel.xls file,
now I need the ability to print to fit on a letter size paper (original is
11x17).

This is my code for print the Excel from Access:

Function printxls(filename As String)
Static xlApp As Variant
Static xlBook As Variant
Static xlSheet As Variant
Static path As String

Set xlApp = CreateObject("Excel.Application")
path = "c:\chart\"

Set xlBook = xlApp.Workbooks.Open(path & filename & ".xls")
Set xlSheet = xlBook.Worksheets(1)
xlSheet.PrintOut
xlBook.Close (False)
xlApp.Quit

Set xlApp = Nothing
Set xlBook = Nothing
End Function


What would I need to do to cause it to print my excel.xls (11x17) to a
letter??

Thanks!

Gary
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default OLE or Automation Printing of Excel

Gary,
I've modified your code a little, to make sure that
Excel exits gracefully, by setting all the object references to
nothing. The print setting additions, I hope, are self-explanatory.

Jim Cone
San Francisco, USA

'-----------------------------
Function printxls(filename As String)
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim objPSU As Excel.PageSetup
Dim strPath As String

Set xlApp = New Excel.Application
strPath = "c:\chart\"
Set xlBook = xlApp.Workbooks.Open(strPath & filename & ".xls")
Set xlSheet = xlBook.Worksheets(1)
Set objPSU = xlSheet.PageSetup

'use only one of the next two lines...
objPSU.Orientation = xlLandscape
'objPSU.Orientation = xlPortrait
objPSU.PaperSize = xlPaperLetter
objPSU.Zoom = False
objPSU.FitToPagesWide = 1
objPSU.FitToPagesTall = False
xlSheet.PrintOut

Set objPSU = Nothing
Set xlSheet = Nothing
xlBook.Close SaveChanges:=False
Set xlBook = Nothing
xlApp.Quit
Set xlApp = Nothing
End Function
'--------------------------------


"Gary"

wrote in message

I need a way to setting up excel to "print to fit" fom MS Access using
Automation or OLE. The VBA code below allows to print the excel.xls file,
now I need the ability to print to fit on a letter size paper (original is
11x17).

This is my code for print the Excel from Access:

Function printxls(filename As String)
Static xlApp As Variant
Static xlBook As Variant
Static xlSheet As Variant
Static path As String
Set xlApp = CreateObject("Excel.Application")
path = "c:\chart\"
Set xlBook = xlApp.Workbooks.Open(path & filename & ".xls")
Set xlSheet = xlBook.Worksheets(1)
xlSheet.PrintOut
xlBook.Close (False)
xlApp.Quit
Set xlApp = Nothing
Set xlBook = Nothing
End Function

What would I need to do to cause it to print my excel.xls (11x17) to a
letter??
Thanks!
Gary
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default OLE or Automation Printing of Excel

With xlSheet
With .PageSetup
.Zoom = False
.FitToPagesTall = 1
.FitToPagesWide = 1
End With
.PrintOut
End With



"Gary" wrote in message
...
I need a way to setting up excel to "print to fit" fom MS Access using
Automation or OLE. The VBA code below allows to print the excel.xls

file,
now I need the ability to print to fit on a letter size paper (original is
11x17).

This is my code for print the Excel from Access:

Function printxls(filename As String)
Static xlApp As Variant
Static xlBook As Variant
Static xlSheet As Variant
Static path As String

Set xlApp = CreateObject("Excel.Application")
path = "c:\chart\"

Set xlBook = xlApp.Workbooks.Open(path & filename & ".xls")
Set xlSheet = xlBook.Worksheets(1)
xlSheet.PrintOut
xlBook.Close (False)
xlApp.Quit

Set xlApp = Nothing
Set xlBook = Nothing
End Function


What would I need to do to cause it to print my excel.xls (11x17) to a
letter??

Thanks!

Gary



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
printing automation wsk Excel Discussion (Misc queries) 0 May 17th 06 02:18 PM
Turn off printing status dialog with Excel automation gm Excel Programming 0 March 21st 05 04:31 PM
Printing Text from Excel Automation Tom Ogilvy Excel Programming 0 August 6th 04 04:07 PM
Excel Web Automation mccaka Excel Programming 1 October 9th 03 02:18 AM


All times are GMT +1. The time now is 06:03 AM.

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

About Us

"It's about Microsoft Excel"