ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   About printing a document (https://www.excelbanter.com/excel-discussion-misc-queries/218798-about-printing-document.html)

FiluDlidu

About printing a document
 
Hi all,

I am looking around to see if anyone would have an idea on how a print job
could be cancelled if a certain cell within the print area has a certain
value or is an error. I would like something that would make something like
the following possible:

- I go to File\Print;
- Cell A1 value being 0 (or being an error, or containing no data), a
message box pops up to tell me the value of cell A1 is to be delt with before
the printing can occur;
- Printing is cancelled;
- I do whatever I have to do to make cell A1 value being valid;
- I go to File\Print;
- I get my usual dialog window, press OK and the document comes out of the
printer.

Any ideas?

Thanks for any thinking, even fruitless, anyone may put on this problem,

Feelu

smartin

About printing a document
 
FiluDlidu wrote:
Hi all,

I am looking around to see if anyone would have an idea on how a print job
could be cancelled if a certain cell within the print area has a certain
value or is an error. I would like something that would make something like
the following possible:

- I go to File\Print;
- Cell A1 value being 0 (or being an error, or containing no data), a
message box pops up to tell me the value of cell A1 is to be delt with before
the printing can occur;
- Printing is cancelled;
- I do whatever I have to do to make cell A1 value being valid;
- I go to File\Print;
- I get my usual dialog window, press OK and the document comes out of the
printer.

Any ideas?

Thanks for any thinking, even fruitless, anyone may put on this problem,

Feelu


Use the BeforePrint event in ThisWorkbook module. Something like this
(untested):

Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Range("A1").Value = 0 Then
Cancel = True
MsgBox "Error to be dealt with"
EndIf
End Sub

Note the code goes in the _Workbook_ module, not a sheet or standard module.

Elkar

About printing a document
 
I've got a Timesheet that I created that does this very thing. It checks
several areas to make sure the employee filled it out correctly before
allowing them to print. Try this VB Code in the Workbook - BeforePrint
section:

Private Sub Workbook_BeforePrint(Cancel As Boolean)

Dim wks As Worksheet
Set wks = Worksheets("Your Worksheet")

If wks.Range("A1") = 0 Then
MsgBox ("Printing canceled due to the following error: Cell A1 may not
equal 0.")
Cancel = True
End If

End Sub

HTH
Elkar


"FiluDlidu" wrote:

Hi all,

I am looking around to see if anyone would have an idea on how a print job
could be cancelled if a certain cell within the print area has a certain
value or is an error. I would like something that would make something like
the following possible:

- I go to File\Print;
- Cell A1 value being 0 (or being an error, or containing no data), a
message box pops up to tell me the value of cell A1 is to be delt with before
the printing can occur;
- Printing is cancelled;
- I do whatever I have to do to make cell A1 value being valid;
- I go to File\Print;
- I get my usual dialog window, press OK and the document comes out of the
printer.

Any ideas?

Thanks for any thinking, even fruitless, anyone may put on this problem,

Feelu


FiluDlidu

About printing a document
 
Note the code goes in the _Workbook_ module, not a sheet or standard module.

Now I understand why this didn't work for me!

Thank you very much for your help.

Feelu


All times are GMT +1. The time now is 07:11 PM.

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