PDA

View Full Version : Forcing printer to print landscape



Croeg
12-24-2006, 08:38 AM
Hi all,

Not sure if this is possible but the code below pulls up a webpage, waits for it to load, prints it...allowing enough time for info to reach the printer before closing down IE. I am trying to force the printer to switch to landscape but not sure if/how this can be done.

Any Ideas ??? :help

Croeg


Sub test()
Dim IeApp As InternetExplorer
Dim sURL As String
Dim IeDoc As Object
Dim i As Long
'Create new instance of IE
Set IeApp = New InternetExplorer

'Make it visible - some things don?t work
'unless it?s visible
IeApp.Visible = True

On Error GoTo EndPrint

sURL = www.cvbaexpress.com (http://www.cvbaexpress.com/)
'navigate to the page
IeApp.navigate sURL

'Pause the macro using a loop until the
'page is fully loaded
Do
Loop Until IeApp.ReadyState = READYSTATE_COMPLETE

Const PRINT_WAITFORCOMPLETION = 2
Const OLECMDEXECOPT_DONTPROMPTUSER = 2
Const OLECMDID_PRINT = 6

IeApp.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, PRINT_WAITFORCOMPLETION, 2

'Clean up
IeApp.Quit
Set IeApp = Nothing

Exit Sub

EndPrint:

'IF WEBSITE NOT RESPONDING

ans = MsgBox("Website not responding.", vbOKOnly)

VRFYSYS.Show

End Sub

Simon Lloyd
12-25-2006, 02:54 AM
I have no idea how to do what you want but i recorded this

Sub Macro1()
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.75)
.RightMargin = Application.InchesToPoints(0.75)
.TopMargin = Application.InchesToPoints(1)
.BottomMargin = Application.InchesToPoints(1)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xllandscape'''''heres the line you want!
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 100
.PrintErrors = xlPrintErrorsDisplayed
End With
End Sub

Regards,
Simon

Croeg
12-25-2006, 10:00 AM
Hi Simon,

Thanks for the response. :beerchug: I think the code you posted will take the active spreadsheet in my excel workbook and format to landscape view. It doesn't recognize the active webpage. So far the best I can come up with is to add the following:


IeApp.ExecWB OLECMDID_PAGESETUP, OLECMDEXECOPT_PROMPTUSER, Null, Null


This will allow the user to select landscape and then the rest of the program will run. If anyone knows of a more automated solution where I can programatically select landscape, that would be fantastic !!!

Thanks,

Croeg

Norie
12-25-2006, 10:19 AM
Croeg

I tried finding a way to do this specifically by searching here. (http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/dhtml_reference_entry.asp)

But I didn't have any luck, though I did find an easier method of displaying the print dialog, just use the print (http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods.asp)method.

Croeg
12-25-2006, 10:48 AM
Hi Norie,

Thanks for the reply! I'll try the print method. Thank you. :) As far as finding a way to automatically print in landscape, I guess I could use the sendkeys method but I'd rather not. Thanks again!


Croeg