Can printing in excel be blocked until data is in a certain cell?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to have a feature in my worksheet that requires a cell to have a
value entered into it before it is possible to print the page, can this be
done with a limited knowledge of Visual Basic programming?
If not perhaps a sample piece of code could be posted to achieve the above.
I am using Excel 2003.
Thankyou
 
If you open the VB Editor, look for your workbook in the project explorer
(usually on the left of the window). Select View, Project Explorer if in
doubt

Open the tree structure against your workbook name
Double-click the ThisWorkbook item - a code pane will open
Paste the code below into the Code pane
'-------<Snippet>
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Range("A1") <> "You may print" Then
Cancel = True
End If
End Sub
'-------</Snippet>

Edit the line beginning "If Activesheet..."
This code prevents printing of the active sheet if Cell A1 does not
contain "You may print" as the entire cell content.

Hope this sets you in the right direction
Roger
Shaftesbury (UK)
 
Thank you Roger,
I am absolutely staggered at how 5 lines of code can solve my dilemna.
I think you've broken the ice with VB for me. :-)
Have a great day.

Glen Loftus
 
Back
Top