Print Macro

G

Guest

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
 
D

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top