PDA

View Full Version : Sleeper: Print User Form



bkudulis
12-06-2004, 02:32 PM
I have created a user form in Excel and would now like to print it. I created a command button with the code (CraneBoard.PrintForm),CraneBoard is the name of the form. The form looks fine on the screen but when it prints it cuts off a pretty big section. I could probably fit it if I was able to change the orientation but cannot seem to do that. I thought that I might be able to do it in VBA but cannot seem to find anything. The other thing is that it prints a gray background but that is not a big deal, I can live with that. Thank you in advance.

johnske
12-06-2004, 03:45 PM
Hi bkudulis, for starters, have you tried Zoom?


CraneBoard.Zoom = 90

Will reduce everything written on the form to 90% (set your own zoom magnification) but this doen't reduce the form itself. - Maybe this'll allow you to print the writing??

HTH

Zack Barresse
12-06-2004, 04:03 PM
Hi,


Try something like this ...



Option Explicit
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)
Private Const VK_LMENU = &HA4
Private Const VK_SNAPSHOT = &H2C
Private Const VK_CONTROL = &H11
Private Const VK_V = &H56
Private Const VK_0x79 = &H79
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2

Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim sAppOs As String
Dim wks As Worksheet
'get oparating system
sAppOs = Application.OperatingSystem
Application.DisplayAlerts = False
Application.ScreenUpdating = False
If Mid(sAppOs, 18, 2) = "NT" Then
' WinNT,Windows2000,WindowsXP - Using Win32API
Call keybd_event(VK_LMENU, VK_V, KEYEVENTF_EXTENDEDKEY, 0)
Call keybd_event(VK_SNAPSHOT, VK_0x79, KEYEVENTF_EXTENDEDKEY, 0)
Call keybd_event(VK_LMENU, VK_V, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)
Call keybd_event(VK_SNAPSHOT, VK_0x79, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)
Else
' Windows95,Windows98,WindowsME
Call keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY, 0)
Call keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)
End If
DoEvents
Unload Me
Set wks = Workbooks.Add.Sheets(1)
Application.Goto wks.Range("A1")
ActiveSheet.Paste
wks.SaveAs Filename:="C:\myfile.htm", FileFormat:=xlHtml
wks.PrintOut copies:=1
wks.Parent.Close False
Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox "Have a look at C:\myfile.files folder."
End Sub



Code written by Masaru Kaji (aka Colo). It is a userform doubleclick event, which saves the userform as a picture file and saves in html format. Customize as desired. :)