Consulting

Results 1 to 5 of 5

Thread: Forcing printer to print landscape

  1. #1
    VBAX Regular
    Joined
    Nov 2006
    Posts
    41
    Location

    Forcing printer to print landscape

    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 ???

    Croeg

    [VBA]
    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
    '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
    [/VBA]

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    I have no idea how to do what you want but i recorded this
    [VBA]
    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

    [/VBA]Regards,
    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    VBAX Regular
    Joined
    Nov 2006
    Posts
    41
    Location

    RE: Forcing printer to print landscape

    Hi Simon,

    Thanks for the response. 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:
    [VBA]

    IeApp.ExecWB OLECMDID_PAGESETUP, OLECMDEXECOPT_PROMPTUSER, Null, Null
    [/VBA]

    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

  4. #4
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Croeg

    I tried finding a way to do this specifically by searching here.

    But I didn't have any luck, though I did find an easier method of displaying the print dialog, just use the print method.

  5. #5
    VBAX Regular
    Joined
    Nov 2006
    Posts
    41
    Location

    RE: Forcing printer to print landscape

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •