ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Before Print (https://www.excelbanter.com/excel-programming/355858-before-print.html)

peabrain25

Before Print
 
Hello,
I am working with a worksheet in which I have inserted a button to print a
form. The button runs a macro which calls a function to check for errors
(missing fields, incorrect data, etc.). If all is well, the form prints. My
problem is that people can still use File, Print to print the form without
checking for errors first. I have tried using the Before_Print object to stop
this from happening by telling it to run the print macro I wrote before
printing everything. The problem with that is that now either two forms print
(one from the File, Print and one from the print macro), or no form prints
(when I set Cancel to be true). Is there a way to disable the manual printing
capabilities for users or is there another way around this? Thanks!

Ron de Bruin

Before Print
 
Use this for "Sheet1"

This example print if there is a value in A1

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "Sheet1" Then
Cancel = True
Application.EnableEvents = False
Application.ScreenUpdating = False
With ActiveSheet
If Range("A1") < "" Then
.PrintOut
End If
End With
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"peabrain25" wrote in message ...
Hello,
I am working with a worksheet in which I have inserted a button to print a
form. The button runs a macro which calls a function to check for errors
(missing fields, incorrect data, etc.). If all is well, the form prints. My
problem is that people can still use File, Print to print the form without
checking for errors first. I have tried using the Before_Print object to stop
this from happening by telling it to run the print macro I wrote before
printing everything. The problem with that is that now either two forms print
(one from the File, Print and one from the print macro), or no form prints
(when I set Cancel to be true). Is there a way to disable the manual printing
capabilities for users or is there another way around this? Thanks!





All times are GMT +1. The time now is 12:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com