Results 1 to 8 of 8

Thread: Printing UserForm using PrintForm

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Location
    Lucenec, Slovakia
    Posts
    154

    Exclamation Printing UserForm using PrintForm

    Hi guys,

    I would like to print my UserForm using PrintForm.

    I found the following code at VBForums. When I try to run it at Printer.Print erites me 424 error code. Could anybody help me?

    Thanks
    Boris

    VB Code:
    1. Option Explicit
    2. 'settings for Print.Screen
    3. Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
    4.           ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    5. Public Const VK_MENU As Byte = &H12
    6. Public Const VK_SNAPSHOT As Byte = &H2C
    7. Public Const KEYEVENTF_KEYUP = &H2
    8.  
    9. Public Sub Image5_Click()
    10.   Printscreen
    11. End Sub
    12. Public Sub Printscreen()
    13. Dim lWidth As Long, lHeight As Long
    14.     'Clipboard.Clear
    15.     Application.CutCopyMode = False
    16.     Call keybd_event(VK_MENU, 0, 0, 0)
    17.     Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
    18.     DoEvents
    19.     Call keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0)
    20.     Call keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0)
    21.     Printer.Print
    22.     If Width > Printer.ScaleWidth Then
    23.         lWidth = Printer.ScaleWidth
    24.         lHeight = (Printer.ScaleWidth / Width) * Height
    25.     Else
    26.         lWidth = Width
    27.         lHeight = Height
    28.     End If
    29.     Printer.PaintPicture Clipboard.GetData, 0, 0, lWidth, lHeight
    30.     Printer.EndDoc
    31. End Sub

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Printing UserForm using PrintForm

    What app are you writting this in? The userform should have a printform method.
    VB Code:
    1. UserForm1.PrintForm
    HTH
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Location
    Lucenec, Slovakia
    Posts
    154

    Re: Printing UserForm using PrintForm

    Quote Originally Posted by RobDog888
    What app are you writting this in? The userform should have a printform method.
    VB Code:
    1. UserForm1.PrintForm
    HTH
    I was trying write this code, but from the printer I received paper, where was written:

    PCL XL error
    Subsystem: TEXT
    Error: IllegalAttributeValue
    Operator: SetFont
    Position: 1795

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Printing UserForm using PrintForm

    Which Office App are you writting this in and is the error from your code or mine?

    Oh ya, and what version?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Location
    Lucenec, Slovakia
    Posts
    154

    Re: Printing UserForm using PrintForm

    Quote Originally Posted by RobDog888
    Which Office App are you writting this in and is the error from your code or mine?

    Oh ya, and what version?

    I have Office XP Professional and as a part of it Visual Basic Editor version 6.3. That writes for your code.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Printing UserForm using PrintForm

    Ok, in your Excel VBA IDE there is no support for the Printer object. So code like this will NOT work.
    VB Code:
    1. Private Sub CommandButton1_Click()
    2.     printer.Print "Test"
    3. End Sub
    I think the only object that supporst the .Print method is the Debug object.

    You dont want to use the UserForm1.PrintForm method?

    One other option may be to write the form out to a rtf file. Then ShellExecute the file for printing.

    HTH
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Location
    Lucenec, Slovakia
    Posts
    154

    Re: Printing UserForm using PrintForm

    Quote Originally Posted by RobDog888
    Ok, in your Excel VBA IDE there is no support for the Printer object. So code like this will NOT work.
    VB Code:
    1. Private Sub CommandButton1_Click()
    2.     printer.Print "Test"
    3. End Sub
    I think the only object that supporst the .Print method is the Debug object.

    You dont want to use the UserForm1.PrintForm method?

    One other option may be to write the form out to a rtf file. Then ShellExecute the file for printing.

    HTH
    As I wrote before, the error message on the paper I had using UserForm.PrintForm code. I would like to use this code, but I do not understand where is the mistake.

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Printing UserForm using PrintForm

    Quote Originally Posted by RobDog888
    Ok, in your Excel VBA IDE there is no support for the Printer object. So code like this will NOT work.

    VB Code:
    1. Private Sub CommandButton1_Click()
    2.     printer.Print "Test"
    3. End Sub
    I had posted earlier that the Printer object is NOT available in the VBA IDE

    So you need to write it out to a file for printing using the ShellExecute API.

    This code is in the VBA IDE, correct?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width