Need help disabling users from printing unless they print with a given macro button

TylerR99

New Member
Joined
Jan 6, 2017
Messages
3
I'm rather new to using VBA and was looking for some help. The issue I'm having currently is that we have a sheet that users input data into, then once complete there is a macro that they can use to print. The macro prints 3 copies and transfers the given data into a log. However users are not using the provided macro and rather just pressing file and printing there or Ctrl+P. Now this bypassed the macro and makes it so the data does not get saved into the log. What can I do using VBA to solve this? Can I disable printing unless the given macro is used? Or is there a way I can add a popup menu that instructs the user to press the macro instead?
 

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,)
You could put this in the ThisWorkbook code module
Code:
' in ThisWorkbook code module

Public PrintViaMacro As Boolean

Private Sub Workbook_BeforePrint(Cancel As Boolean)
    If Not PrintViaMacro Then
        Cancel = True
        MsgBox "Print this file using the macro"
    End If
    PrintViaMacro = False
End Sub

And then modify your existing print macro just a bit.

Code:
Sub myPrintMacro()
    ' do stuff
    
    ThisWorkbook.PrintViaMacro = True: Rem add this line <<<<<<<<<<<<<
    ActiveSheet.PrintOut
    
    ' do more stuff
End Sub
 
Upvote 0
That worked exactly like I needed thanks. Would there be a way that I could cause that to affect only one sheet?
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,101
Members
449,205
Latest member
ralemanygarcia

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