+ Reply to Thread
Results 1 to 8 of 8

Printing Userforms

  1. #1
    Greg B
    Guest

    Printing Userforms

    Hi all,

    I asked earlier about Printing userforms

    The trouble is I need the form to print in landscape

    How do I do this?

    Thanks in advance

    Greg




  2. #2
    Forum Contributor
    Join Date
    12-11-2004
    MS-Off Ver
    2007
    Posts
    137
    Hello Greg

    I hope this help you
    the macro copy the UserForm in a temporary Word doc and print it in Landscape



    Private Declare Sub keybd_event Lib "user32" ( _
    ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, _
    ByVal dwExtraInfo As Long)

    Private Sub CommandButton1_Click()
    'test with WinXP et Excel2002
    'activate microsoft Word xx.x Object Library
    Dim Wrd As Word.Application
    Dim WrdDoc As Word.Document

    'copy USF
    keybd_event vbKeySnapshot, 1, 0&, 0&
    DoEvents

    Set Wrd = CreateObject("Word.Application") 'create Word session
    On Error Resume Next
    Set WrdDoc = Wrd.Documents.Add
    Wrd.Visible = False
    WrdDoc.PageSetup.Orientation = wdOrientLandscape

    Wrd.Selection.PasteSpecial 'paste in Word doc
    WrdDoc.PrintOut 'print

    WrdDoc.Close False
    WrdDoc.Quit

    End Sub



    Regards ,
    michel

  3. #3
    Dave Peterson
    Guest

    Re: Printing Userforms

    This was posted by Tom Ogilvy:

    Modification of code originally posted by
    "Orlando Magalhães Filho" <[email protected]>

    Modified to capture just the userform (not the whole window).

    In a general module:

    Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
    ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

    Public Const VK_SNAPSHOT = 44
    Public Const VK_LMENU = 164
    Public Const KEYEVENTF_KEYUP = 2
    Public Const KEYEVENTF_EXTENDEDKEY = 1


    Sub Test()
    UserForm1.Show
    End Sub


    In the userform module:

    Private Sub CommandButton1_Click()
    ' keybd_event VK_SNAPSHOT, 0, 0, 0
    DoEvents
    keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY, 0
    keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY, 0
    keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY + _
    KEYEVENTF_KEYUP, 0
    keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY + _
    KEYEVENTF_KEYUP, 0
    DoEvents
    Workbooks.Add
    Application.Wait Now + TimeValue("00:00:01")
    ActiveSheet.PasteSpecial Format:="Bitmap", Link:=False, _
    DisplayAsIcon:=False
    ActiveSheet.Range("A1").Select
    'added to force landscape
    ActiveSheet.PageSetup.orientation = xlLandscape
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    ActiveWorkbook.Close False
    End Sub

    I added a line that changed the orientation to landscape.

    Greg B wrote:
    >
    > Hi all,
    >
    > I asked earlier about Printing userforms
    >
    > The trouble is I need the form to print in landscape
    >
    > How do I do this?
    >
    > Thanks in advance
    >
    > Greg


    --

    Dave Peterson

  4. #4
    Registered User
    Join Date
    01-15-2004
    Posts
    10

    Unhappy

    undefined
    Quote Originally Posted by Dave Peterson
    This was posted by Tom Ogilvy:

    Modification of code originally posted by
    "Orlando Magalhães Filho" <[email protected]>

    Modified to capture just the userform (not the whole window).

    In a general module:

    Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
    ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

    Public Const VK_SNAPSHOT = 44
    Public Const VK_LMENU = 164
    Public Const KEYEVENTF_KEYUP = 2
    Public Const KEYEVENTF_EXTENDEDKEY = 1


    Sub Test()
    UserForm1.Show
    End Sub


    In the userform module:

    Private Sub CommandButton1_Click()
    ' keybd_event VK_SNAPSHOT, 0, 0, 0
    DoEvents
    keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY, 0
    keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY, 0
    keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY + _
    KEYEVENTF_KEYUP, 0
    keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY + _
    KEYEVENTF_KEYUP, 0
    DoEvents
    Workbooks.Add
    Application.Wait Now + TimeValue("00:00:01")
    ActiveSheet.PasteSpecial Format:="Bitmap", Link:=False, _
    DisplayAsIcon:=False
    ActiveSheet.Range("A1").Select
    'added to force landscape
    ActiveSheet.PageSetup.orientation = xlLandscape
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    ActiveWorkbook.Close False
    End Sub

    I added a line that changed the orientation to landscape.

    Greg B wrote:
    >
    > Hi all,
    >
    > I asked earlier about Printing userforms
    >
    > The trouble is I need the form to print in landscape
    >
    > How do I do this?
    >
    > Thanks in advance
    >
    > Greg


    --

    Dave Peterson
    this was just what i was looking for ?? i thought
    i have a simular problem in which i have an excel form in which i need to print landscape.
    can the above solution be altered to use with excel

  5. #5
    Dave Peterson
    Guest

    Re: Printing Userforms

    It does use excel.



    alexanderd wrote:
    >
    > undefinedDave Peterson Wrote:
    > > This was posted by Tom Ogilvy:
    > >
    > > Modification of code originally posted by
    > > "Orlando Magalhães Filho" <[email protected]>
    > >
    > > Modified to capture just the userform (not the whole window).
    > >
    > > In a general module:
    > >
    > > Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
    > > ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    > >
    > > Public Const VK_SNAPSHOT = 44
    > > Public Const VK_LMENU = 164
    > > Public Const KEYEVENTF_KEYUP = 2
    > > Public Const KEYEVENTF_EXTENDEDKEY = 1
    > >
    > >
    > > Sub Test()
    > > UserForm1.Show
    > > End Sub
    > >
    > >
    > > In the userform module:
    > >
    > > Private Sub CommandButton1_Click()
    > > ' keybd_event VK_SNAPSHOT, 0, 0, 0
    > > DoEvents
    > > keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY, 0
    > > keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY, 0
    > > keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY + _
    > > KEYEVENTF_KEYUP, 0
    > > keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY + _
    > > KEYEVENTF_KEYUP, 0
    > > DoEvents
    > > Workbooks.Add
    > > Application.Wait Now + TimeValue("00:00:01")
    > > ActiveSheet.PasteSpecial Format:="Bitmap", Link:=False, _
    > > DisplayAsIcon:=False
    > > ActiveSheet.Range("A1").Select
    > > 'added to force landscape
    > > ActiveSheet.PageSetup.orientation = xlLandscape
    > > ActiveWindow.SelectedSheets.PrintOut Copies:=1
    > > ActiveWorkbook.Close False
    > > End Sub
    > >
    > > I added a line that changed the orientation to landscape.
    > >
    > > Greg B wrote:
    > > >
    > > > Hi all,
    > > >
    > > > I asked earlier about Printing userforms
    > > >
    > > > The trouble is I need the form to print in landscape
    > > >
    > > > How do I do this?
    > > >
    > > > Thanks in advance
    > > >
    > > > Greg

    > >
    > > --
    > >
    > > Dave Peterson

    > this was just what i was looking for ?? i thought
    > i have a simular problem in which i have an excel form in which i need
    > to print landscape.
    > can the above solution be altered to use with excel
    >
    > --
    > alexanderd
    > ------------------------------------------------------------------------
    > alexanderd's Profile: http://www.excelforum.com/member.php...fo&userid=4984
    > View this thread: http://www.excelforum.com/showthread...hreadid=353789


    --

    Dave Peterson

  6. #6
    Registered User
    Join Date
    07-16-2018
    Location
    Geneva Switzerland
    MS-Off Ver
    Excel 2016
    Posts
    7

    Re: Printing Userforms

    Hi everybody, it's my first question.
    English isn't my mothertongue, sorry for volapück sentences.
    I hope this very old thread will come back to action !
    I'm trying to get a print or an image of a userform trigged with VBA code and made many
    attempts but I got only two bad results: if I write "my_userform.show" without a zero,
    the execution of my code stops when the USF pops up and if I add a zero I get an image
    of my VBA code ! I feel a bit like that beginning photographer which shooted each time his tie !
    Where do I wrong ?
    Thank you in advance for any good idea.
    regards
    Pierre

  7. #7
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Re: Printing Userforms

    Good evening pierruel

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.

  8. #8
    Registered User
    Join Date
    07-16-2018
    Location
    Geneva Switzerland
    MS-Off Ver
    Excel 2016
    Posts
    7

    Re: Printing Userforms

    Good evening dominicb,
    Sorry to have broken a rule. I read accurately the general ones you've to read on registering but not the forum rules (I didn't simply notice them). A beginners' foul. Now I did and shall obey them. Since then I started a new thread and hope I'll have answers. Since the existing thread in this case was not particularly relevant, just on a similar issue, I didn't provide a link. Not easy to cope when in a foreing language !
    Best regards
    Pierre (alias pierruel)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1