ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Print Macro (https://www.excelbanter.com/excel-discussion-misc-queries/2211-print-macro.html)

NICK

Print Macro
 
Hello

I would like to write a macro, for a particular workbook, which is activated
when you select File/Print/OK (the macro will check to see if certain
conditions are met and will print if they are but will return an error
message if they are not). Can anyone suggest the code required?

Thanks in advance
Nick

Dave Peterson

There's a workbook event that you can tie into.

Rightclick on the excel icon (to the left of the File option on the worksheet
menu bar).

Select view code and paste this in the code window:

Option Explicit
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If LCase(Me.Worksheets("sheet1").Range("a1").Value) < "oktoprint" Then
MsgBox "Can't print"
Cancel = True
Else
'do nothing, ok to print
End If
End Sub

You can add any checks you want inside this procedure.



NICK wrote:

Hello

I would like to write a macro, for a particular workbook, which is activated
when you select File/Print/OK (the macro will check to see if certain
conditions are met and will print if they are but will return an error
message if they are not). Can anyone suggest the code required?

Thanks in advance
Nick


--

Dave Peterson


All times are GMT +1. The time now is 04:36 AM.

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