Solved

How do I print in landscape?

Posted on 2004-09-19
9
2,856 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 Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month2 days, 18 hours left to enroll

621 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