Solved

How do I print in landscape?

Posted on 2004-09-19
9
2,819 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
Comment Utility
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
Comment Utility
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
Comment Utility
what is HTHAB?
0
 
LVL 1

Author Comment

by:shaolinfunk
Comment Utility
is it object.regread and object.regwrite? what is the object?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 44

Expert Comment

by:bruintje
Comment Utility
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
Comment Utility
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
Comment Utility
Is there a way to print Landscape without editing the Registry?
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
no, looked for that at the start
0
 

Expert Comment

by:Magnum13Yancey
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now