|
-
Feb 3rd, 2005, 09:20 AM
#1
Thread Starter
Addicted Member
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
-
Feb 3rd, 2005, 03:04 PM
#2
Re: Printing UserForm using PrintForm
What app are you writting this in? The userform should have a printform method.
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Feb 4th, 2005, 01:04 AM
#3
Thread Starter
Addicted Member
Re: Printing UserForm using PrintForm
 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
-
Feb 4th, 2005, 01:09 AM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Feb 4th, 2005, 02:26 AM
#5
Thread Starter
Addicted Member
Re: Printing UserForm using PrintForm
 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.
-
Feb 4th, 2005, 12:29 PM
#6
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
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Feb 7th, 2005, 02:07 AM
#7
Thread Starter
Addicted Member
Re: Printing UserForm using PrintForm
 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.
-
Feb 7th, 2005, 12:06 PM
#8
Re: Printing UserForm using PrintForm
 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?
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|