Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Print a Userform To Fit On One Page

I would like to print a userform with a commandbutton, but the entire
userform does not fit on the page. Is there a way to click the control
button that is located on the userform and print the form to fit on one page?

This is what I have:

Private Sub btnPrint_Click()

frmItemSummary.PrintForm
MsgBox "Item # " & Cells(ActiveCell.Row, "A") & " has been sent to the
Printer.", vbInformation

End Sub
--
Cheers,
Ryan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default Print a Userform To Fit On One Page

I tweaked some code by Tom Ogilvy code. It copies the userform to a
worksheet and then prints it from there.

'In a general VBA module:
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_SNAPSHOT = 44
Public Const VK_LMENU = 164
Public Const KEYEVENTF_KEYUP = 2
Public Const KEYEVENTF_EXTENDEDKEY = 1

Sub Test()
UserForm1.Show
End Sub

'In the userform module:
Private Sub CommandButton1_Click()
' keybd_event VK_SNAPSHOT, 0, 0, 0
DoEvents
keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY, 0
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY, 0
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY + _
KEYEVENTF_KEYUP, 0
keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY + _
KEYEVENTF_KEYUP, 0
DoEvents
Workbooks.Add
Application.Wait Now + TimeValue("00:00:01")
ActiveSheet.PasteSpecial Format:="Bitmap", Link:=False, _
DisplayAsIcon:=False
ActiveSheet.Range("A1").Select
With ActiveSheet.PageSetup
.Orientation = xlPortrait
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
ActiveWindow.SelectedSheets.PrintOut Copies:=1
ActiveWorkbook.Close False
End Sub

If desired, change the .Orientation value to xlLandscape.
Hope this helps,

Hutch

"RyanH" wrote:

I would like to print a userform with a commandbutton, but the entire
userform does not fit on the page. Is there a way to click the control
button that is located on the userform and print the form to fit on one page?

This is what I have:

Private Sub btnPrint_Click()

frmItemSummary.PrintForm
MsgBox "Item # " & Cells(ActiveCell.Row, "A") & " has been sent to the
Printer.", vbInformation

End Sub
--
Cheers,
Ryan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Print a Userform To Fit On One Page

Maybe resize the userform before printing to shrink it to within the page
breaks?

"RyanH" wrote:

I would like to print a userform with a commandbutton, but the entire
userform does not fit on the page. Is there a way to click the control
button that is located on the userform and print the form to fit on one page?

This is what I have:

Private Sub btnPrint_Click()

frmItemSummary.PrintForm
MsgBox "Item # " & Cells(ActiveCell.Row, "A") & " has been sent to the
Printer.", vbInformation

End Sub
--
Cheers,
Ryan

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Print a Userform To Fit On One Page

I think I have seen this code from Tom Ogilvy before. It works great. Do
you know how to explain most of the lines of code here? I would like to
understand what is happening here instead of just copying it.
--
Cheers,
Ryan


"Tom Hutchins" wrote:

I tweaked some code by Tom Ogilvy code. It copies the userform to a
worksheet and then prints it from there.

'In a general VBA module:
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_SNAPSHOT = 44
Public Const VK_LMENU = 164
Public Const KEYEVENTF_KEYUP = 2
Public Const KEYEVENTF_EXTENDEDKEY = 1

Sub Test()
UserForm1.Show
End Sub

'In the userform module:
Private Sub CommandButton1_Click()
' keybd_event VK_SNAPSHOT, 0, 0, 0
DoEvents
keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY, 0
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY, 0
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY + _
KEYEVENTF_KEYUP, 0
keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY + _
KEYEVENTF_KEYUP, 0
DoEvents
Workbooks.Add
Application.Wait Now + TimeValue("00:00:01")
ActiveSheet.PasteSpecial Format:="Bitmap", Link:=False, _
DisplayAsIcon:=False
ActiveSheet.Range("A1").Select
With ActiveSheet.PageSetup
.Orientation = xlPortrait
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
ActiveWindow.SelectedSheets.PrintOut Copies:=1
ActiveWorkbook.Close False
End Sub

If desired, change the .Orientation value to xlLandscape.
Hope this helps,

Hutch

"RyanH" wrote:

I would like to print a userform with a commandbutton, but the entire
userform does not fit on the page. Is there a way to click the control
button that is located on the userform and print the form to fit on one page?

This is what I have:

Private Sub btnPrint_Click()

frmItemSummary.PrintForm
MsgBox "Item # " & Cells(ActiveCell.Row, "A") & " has been sent to the
Printer.", vbInformation

End Sub
--
Cheers,
Ryan

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting the print area in page set up to print 1 page wide by 2 pages tall EA[_2_] Excel Discussion (Misc queries) 2 July 12th 07 08:39 PM
PRINT PAGE BREAK VIEW AS WATERMARK FIOR EACH PAGE RALPH Setting up and Configuration of Excel 3 March 16th 06 11:08 PM
Print all pages in a Multi page userform Alro Excel Programming 5 September 6th 05 10:49 PM
How to print a page of a multipage userform Jean-Pierre D via OfficeKB.com Excel Programming 3 August 15th 05 05:29 PM
Hide a page in a multi page userform Ian Mangelsdorf Excel Programming 1 October 27th 04 09:06 AM


All times are GMT +1. The time now is 05:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"