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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,224,828
Messages
6,181,213
Members
453,024
Latest member
Wingit77

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