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:
Option Explicit
'settings for Print.Screen
Public 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_MENU As Byte = &H12
Public Const VK_SNAPSHOT As Byte = &H2C
Public Const KEYEVENTF_KEYUP = &H2
Public Sub Image5_Click()
Printscreen
End Sub
Public Sub Printscreen()
Dim lWidth As Long, lHeight As Long
'Clipboard.Clear
Application.CutCopyMode = False
Call keybd_event(VK_MENU, 0, 0, 0)
Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
DoEvents
Call keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0)
Call keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0)
Printer.Print
If Width > Printer.ScaleWidth Then
lWidth = Printer.ScaleWidth
lHeight = (Printer.ScaleWidth / Width) * Height
Else
lWidth = Width
lHeight = Height
End If
Printer.PaintPicture Clipboard.GetData, 0, 0, lWidth, lHeight
Printer.EndDoc
End Sub
Re: Printing UserForm using PrintForm
What app are you writting this in? The userform should have a printform method.
HTH
Re: Printing UserForm using PrintForm
Quote:
Originally Posted by RobDog888
What app are you writting this in? The userform should have a printform method.
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
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?
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.
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:
Private Sub CommandButton1_Click()
printer.Print "Test"
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
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:
Private Sub CommandButton1_Click()
printer.Print "Test"
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.
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:
Private Sub CommandButton1_Click()
printer.Print "Test"
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?