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