Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I print in landscape?

Posted on 2004-09-19
9
Medium Priority
?
2,879 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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

783 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