Count of No of Page to be Printed with YES or NO options

Nasmin Saheed

New Member
Joined
Jun 11, 2015
Messages
49
Office Version
  1. 365
Platform
  1. Windows
I have written a VBA script to print some details using a loop option, and this VBA script is assigned to a button. Now, I need that when I press the button to print the details, the VBA should calculate how many pages will be printed and it should display a message with two options: YES or NO. If I press YES, all the pages should print. If I press NO, then the pages should not print. Can anyone please assist with this?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Would something like this in the ThisWorkbook module help?

VBA Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
  Dim pp As Long
  Dim Resp As VbMsgBoxResult
 
  pp = ExecuteExcel4Macro("GET.DOCUMENT(50)")
  Resp = MsgBox(Prompt:=pp & " Pages will be printed. Continue?", Buttons:=vbYesNo)
  If Resp = vbYes Then
    Application.EnableEvents = False
    ActiveSheet.PrintOut
    Application.EnableEvents = True
  Else
    Cancel = True
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,346
Members
452,638
Latest member
Oluwabukunmi

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