Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 20th, 2004, 10:49 PM
Registered User
 
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default PrintForm

I need to be implement a feature that sends a screen print of an Excel 2000 VBA form to the printer upon clicking on a button. I am using the 'PrintForm' feature i.e. frmMainForm.Printform

I have encountered the following problems:
1. Certain frame captions are not printing out
2. The form prints in portrait mode, therefore cutting off parts of the form.

Is there a way to make the form print in landscape mode and fix the problem with the captions? Ideally I would also like to be able to add a header and footer.

Regards



 
Old October 21st, 2004, 12:27 AM
Registered User
 
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I went digging and found this code on another forum. I've tested it and it works to fix the problem of shrinking the form so that it fits on the printed page.

'=================
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 KEYEVENTF_KEYUP = &H2
Private Const VK_SNAPSHOT = &H2C
Private Const VK_MENU = &H12

'================================================= ====================

Private Sub CommandButton1_Click()

Dim wb As Workbook
Dim sh As Worksheet

CommandButton1.SetFocus
AltPrintScreen
DoEvents

Application.ScreenUpdating = False

Set wb = Workbooks.Add(template:=xlWBATWorksheet)
Set sh = wb.Sheets(1)

sh.Paste

With sh.PageSetup
    .FitToPagesTall = 1
    .FitToPagesWide = 1
    .Orientation = xlPortrait
    .Zoom = False
End With

sh.PrintOut

wb.Close False

Application.ScreenUpdating = True

Set sh = Nothing
Set wb = Nothing

End Sub

'================================================= =========================

Private Sub AltPrintScreen()
    keybd_event VK_MENU, 0, 0, 0
    keybd_event VK_SNAPSHOT, 0, 0, 0
    keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0
    keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
End Sub




 
Old March 29th, 2006, 12:26 PM
Registered User
 
Join Date: Mar 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I discovered that you can call on WordBasic to solve the problem for you in Word:

WordBasic.SendKeys "{1068}"

This sends an image of the form to the clipboard.

From there, you can paste it from the clipboard manually into a document and print the page.

You can automate the document creation, pasting, and printing process, too, if you do not want to do it manually.

Of course, the best solution would be a patch for VBA's PrintForm function.






Similar Threads
Thread Thread Starter Forum Replies Last Post
VB6 PrintForm method too slow bwhit VB How-To 0 May 2nd, 2006 02:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.