Before Print Not Firing

Plukey

Board Regular
Joined
Apr 19, 2019
Messages
138
Office Version
  1. 2016
Platform
  1. Windows
The code used to work & now it has just stopped, not sure what happened. I have a button on the sheet that prints 4 copies. The sheet is a invoice and at the bottom the user is supposed to enter page 1 of 1 .
Listed below are two codes first is the one that i use, & the second is one i just tried that doesn't work either. The code is in This Workbook / Before Print. I'm running 2016...I did read where before print doesn't work with 2013 & later..?

VBA Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "Blank 195" Then
    If Sheets("Blank 195").Range("A38").Value = "" Then
    If Sheets("Blank 195").Range("C38").Value = "" Then
    MsgBox "More info needed Please select Page 1 of 1 ", vbCritical
        Cancel = True
    End If
End If
End Sub
VBA Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "Blank 195" Then

Dim jRange As Range
Set jRange = Sheets("Template").Range("A38,C38")


Dim ReqFields As Boolean

For Each cell In jRange

    If cell.Value = "" Then
        ReqFields = True

    End If
Next

If ReqFields Then

MsgBox ("Cannot leave Page 1 of 1 Blank, More info needed Please select Page 1 of 1"), vbCritical
        Cancel = True
End If

End If

End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Before_Print never stopped working. Whatever you read is wrong.

Your first code is invalid. It won't compile. You have three If statements but only two End If statements. This can't possibly have been working before.

What do you mean by "doesn't work"? Does the code run but not do what you expect? Does the code not run? How do you whether the code is running? What happens when you print?

However, your two versions are doing two very different things.

Your first version is checking cells in Blank 195. If BOTH A38 AND C38 are blank, printing is cancelled.

Your second version is checking cells in Template. If EITHER A38 OR C38 is blank, printing is cancelled.

Please describe what you actually want to happen.
 
Upvote 0
I set up a file like you described and this version of the code works perfectly for me.
VBA Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
   If ActiveSheet.Name = "Blank 195" Then
      If Sheets("Blank 195").Range("A38").Value = "" Or _
         Sheets("Blank 195").Range("C38").Value = "" Then
         MsgBox "More info needed Please select Page 1 of 1 ", vbCritical
         Cancel = True
      End If
   End If
End Sub

File attached
 
Upvote 0
Solution
Before_Print never stopped working. Whatever you read is wrong.

Your first code is invalid. It won't compile. You have three If statements but only two End If statements. This can't possibly have been working before.

What do you mean by "doesn't work"? Does the code run but not do what you expect? Does the code not run? How do you whether the code is running? What happens when you print?

However, your two versions are doing two very different things.

Your first version is checking cells in Blank 195. If BOTH A38 AND C38 are blank, printing is cancelled.

Your second version is checking cells in Template. If EITHER A38 OR C38 is blank, printing is cancelled.

Please describe what you actually want to happen.
Thank you for looking into this with me. Apologies for the errors I gotta slow down...I screwed it up while trying different variations & some how dropped one of the (End If) & overlooked the 2nd codes Sheet Name.
Your correct about the 2013 & later, It was print preview that I read that wouldn't trigger the before print for testing. It was on google, so it had to be true right :)

Anyway, Its working now ... I just switched my code for your latest code & its working again.... actually they're all working now. Shaking my head...I want to say thanks for being patient, this site has some very skilled people. I'm barley scratching the surface when it comes to Excel & I'm definitely guilty for trying to find the quick fix. But I'm trying to figure these things out for myself.
 
Upvote 0

Forum statistics

Threads
1,213,557
Messages
6,114,293
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top