Solved

How do I print in landscape?

Posted on 2004-09-19
9
2,848 Views
Last Modified: 2013-12-26
I have a file "c:\abc.htm".

From my VB app I want to let the user push a button and print that file to a printer in landscape orientation:

I currently use this line when user clicks the command button:

 WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0
   
0
Comment
Question by:shaolinfunk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 12095786
you could have a look at
title : Printing Landscape w/web browser control
source : http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=e87oNziFBHA.1420%40tkmsftngp04

HTHAB

shaolinfunk hehe, nice handle ;)
0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 12096424
thanks for the URL.  what is regread and regwrite?
why is everything after "Dim retVal" highlighted in red in my VB editor?
0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 12096431
what is HTHAB?
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 1

Author Comment

by:shaolinfunk
ID: 12096436
is it object.regread and object.regwrite? what is the object?
0
 
LVL 44

Expert Comment

by:bruintje
ID: 12096439
because of the line breaks, here is an edited version

Option Explicit

'------------------
Public Function setOrientation(ByVal theOrientation As String) As String
    ' changes the printers orientation and returns the old value.
    Dim retVal
    setOrientation = RegRead("Software\Microsoft\Internet Explorer\PageSetup", "orientation")
    retVal = RegWrite("Software\Microsoft\Internet Explorer\PageSetup", "orientation", theOrientation)
End Function
'------------------

Private Sub test()

'Example of use
Dim originalOrientation As String

'Set the oreintation to landscape
originalOrientation = modPrinter.setOrientation("2")

'Print the document
webbrowser1.SetFocus
webbrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0

'Change the orientation back to the original orientation
originalOrientation = modPrinter.setOrientation(printDefaultOrientation)

End Sub

' Here are some other functions that may be of use to you: HTH Steven Allen  (dybrn)
'-----------------
'Found at http://support.microsoft.com/support/kb/articles/Q236/7/77.ASP

'For Page Margins, Microsoft Internet Explorer first
'tries to get the values from this registry key:
'HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup

'If there is no such a key, Internet Explorer create
'this key by copying the values from the following:
'HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\PageSetup

'If there is no such key, default values are provided.

'For the Header and Footer, the values are picked up from the following:
'HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup

'If there is no such key, default values are provided.
'The defaults are
    ' Margins:  0.75
    ' Header:   &w&bPage &p of &P
    ' Footer:   &u&b&d

'For the Internet Explorer default printer, default values are provided
from:
'HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup\printer

Public Type printerMargins
    margin_left As String
    margin_right As String
    margin_top As String
    margin_bottom As String
End Type

Public Function setOrientation(ByVal theOrientation As String) As String
    ' changes the printers orientation and returns the old value.
    Dim retVal
    setOrientation = RegRead("Software\Microsoft\Internet Explorer\PageSetup", "orientation")
    retVal = RegWrite("Software\Microsoft\Internet Explorer\PageSetup", "orientation", theOrientation)
End Function

Public Function setHeader(ByVal theHeader As String) As String
    ' changes the header and returns the old value.
    Dim retVal
    setHeader = RegRead("Software\Microsoft\Internet Explorer\PageSetup", "header")
    retVal = RegWrite("Software\Microsoft\Internet Explorer\PageSetup", "header", theHeader)
End Function

Public Function setFooter(ByVal theFooter As String) As String
    ' changes the Footer and returns the old value.
    Dim retVal
    setFooter = RegRead("Software\Microsoft\Internet Explorer\PageSetup", "Footer")
    retVal = RegWrite("Software\Microsoft\Internet Explorer\PageSetup", "Footer", theFooter)
End Function

Public Function SetDuplex(ByVal theValue As String) As String
    ' Turns on or off the duplexer depending on "theValue".
    Dim retVal
    Dim newValue As String

    If theValue = "2" Then
        newValue = "2" 'ON
    Else
        newValue = "1" 'OFF
    End If
    SetDuplex = RegRead("Software\Microsoft\Internet Explorer\PageSetup", "duplex")
    retVal = RegWrite("Software\Microsoft\Internet Explorer\PageSetup", "duplex", newValue)
End Function

Public Function SetMargins(thePrinterMargins As printerMargins) As printerMargins
    Dim retVal

    SetMargins.margin_left = RegRead("Software\Microsoft\Internet Explorer\PageSetup", "margin_left")
    SetMargins.margin_right = RegRead("Software\Microsoft\Internet Explorer\PageSetup", "margin_right")
    SetMargins.margin_top = RegRead("Software\Microsoft\Internet Explorer\PageSetup", "margin_top")
    SetMargins.margin_bottom = RegRead("Software\Microsoft\Internet Explorer\PageSetup", "margin_bottom")

    retVal = RegWrite("Software\Microsoft\Internet Explorer\PageSetup", "margin_left", thePrinterMargins.margin_left)
    retVal = RegWrite("Software\Microsoft\Internet Explorer\PageSetup", "margin_right", thePrinterMargins.margin_right)
    retVal = RegWrite("Software\Microsoft\Internet Explorer\PageSetup", "margin_top", thePrinterMargins.margin_top)
    retVal = RegWrite("Software\Microsoft\Internet Explorer\PageSetup", "margin_bottom", thePrinterMargins.margin_bottom)

End Function
0
 
LVL 44

Accepted Solution

by:
bruintje earned 50 total points
ID: 12096472
ok this should help a bit

first download the registry unit from
http://www.buygold.net/v01n05/v01n05.html

add the treg *.bas to your project

' ---------------------
' then this part goes into a new module
' ---------------------
Public Type printerMargins
    margin_left As String
    margin_right As String
    margin_top As String
    margin_bottom As String
End Type

Public Function setOrientation(ByVal theOrientation As String) As String
    ' changes the printers orientation and returns the old value.
    Dim retVal
    setOrientation = RegRead("Software\Microsoft\Internet Explorer\PageSetup", "orientation")
    retVal = RegWrite("Software\Microsoft\Internet Explorer\PageSetup", "orientation", theOrientation)
End Function

Public Function setHeader(ByVal theHeader As String) As String
    ' changes the header and returns the old value.
    Dim retVal
    setHeader = RegRead("Software\Microsoft\Internet Explorer\PageSetup", "header")
    retVal = RegWrite("Software\Microsoft\Internet Explorer\PageSetup", "header", theHeader)
End Function

Public Function setFooter(ByVal theFooter As String) As String
    ' changes the Footer and returns the old value.
    Dim retVal
    setFooter = RegRead("Software\Microsoft\Internet Explorer\PageSetup", "Footer")
    retVal = RegWrite("Software\Microsoft\Internet Explorer\PageSetup", "Footer", theFooter)
End Function

Public Function SetDuplex(ByVal theValue As String) As String
    ' Turns on or off the duplexer depending on "theValue".
    Dim retVal
    Dim newValue As String

    If theValue = "2" Then
        newValue = "2" 'ON
    Else
        newValue = "1" 'OFF
    End If
    SetDuplex = RegRead("Software\Microsoft\Internet Explorer\PageSetup", "duplex")
    retVal = RegWrite("Software\Microsoft\Internet Explorer\PageSetup", "duplex", newValue)
End Function

Public Function SetMargins(thePrinterMargins As printerMargins) As printerMargins
    Dim retVal

    SetMargins.margin_left = RegRead("Software\Microsoft\Internet Explorer\PageSetup", "margin_left")
    SetMargins.margin_right = RegRead("Software\Microsoft\Internet Explorer\PageSetup", "margin_right")
    SetMargins.margin_top = RegRead("Software\Microsoft\Internet Explorer\PageSetup", "margin_top")
    SetMargins.margin_bottom = RegRead("Software\Microsoft\Internet Explorer\PageSetup", "margin_bottom")

    retVal = RegWrite("Software\Microsoft\Internet Explorer\PageSetup", "margin_left", thePrinterMargins.margin_left)
    retVal = RegWrite("Software\Microsoft\Internet Explorer\PageSetup", "margin_right", thePrinterMargins.margin_right)
    retVal = RegWrite("Software\Microsoft\Internet Explorer\PageSetup", "margin_top", thePrinterMargins.margin_top)
    retVal = RegWrite("Software\Microsoft\Internet Explorer\PageSetup", "margin_bottom", thePrinterMargins.margin_bottom)

End Function

Public Sub test()

'Example of use
Dim originalOrientation As String
Dim modPrinter As Printer

'Set the oreintation to landscape
originalOrientation = setOrientation("2")

'Print the document
webbrowser1.SetFocus
webbrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0

'Change the orientation back to the original orientation
originalOrientation = setOrientation(printDefaultOrientation)

End Sub
' ---------------------

' ---------------------
' this goes in the click
' ---------------------
Private Sub Command1_Click()
  Call test
End Sub
' ---------------------

away for a few hours now
0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 12098971
Is there a way to print Landscape without editing the Registry?
0
 
LVL 44

Expert Comment

by:bruintje
ID: 12130412
no, looked for that at the start
0
 

Expert Comment

by:Magnum13Yancey
ID: 22140561
The method above works farely well, but has anyone had issues when setting orientation? I'm on vista with IE7 and when I change the orientation value to 2 instead of 1 my document still prints in portrait. Does IE7 look in a different spot for the orientation?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question