Prevent printing by excel normal feature & save worksheet in pdf by a command button

Atiqul Haque

New Member
Joined
Dec 13, 2020
Messages
45
Office Version
  1. 2016
Platform
  1. Windows
Dear All,

I want to prevent printing of worksheet by excel normal feature and allow only to save and print the worksheet as pdf by a command button.
Would you pls solve this problem for me. Your help will be highly appreciated.

i use the following code's but unfortunately when i put the prevent print code in workbook module i can't make the workbook saved as pdf.

Code in workbook module:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
MsgBox "Please print via [Print] or [Pdf] button"
Cancel = True
End Sub

Code in Command Button:
Sub createPDF()
Sheet2.Range("A7:M37").ExportAsFixedFormat xlTypePDF, Filename:= _
"C:\Users\User\Desktop\Save File As PDF\" & Range("C9") & "-" & Range("C10") & "_" & Range("I10") & "_" & "Biochemical_Report", _
OpenAfterPublish:=True
End Sub
 
You can use the code you already have & then add something to the end to print the sheet.
Just use the macro recorder to record yourself printing the sheet & you will have that code.
Thank you very much Sir.
Actually i'm new in codding, so it's difficult for me to understand you advice. It will be helpful for me if you can send me the details code and of course at your convenient.
Best regards and thanks in advance.
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Just turn on the Macro recorder, select the data you want to print & print it, then stop the recorder & you will have the code you need.
 
Upvote 0
Just turn on the Macro recorder, select the data you want to print & print it, then stop the recorder & you will have the code you need.
Thank you sir,
But when i start the macro recorder, command buttons/print button does not work?
 
Upvote 0
You can use Ctrl P to print the sheet when using the recorder.
 
Upvote 0
Then disable the code first.
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0
Good Evening Sir,

I'm here to bother you once again. Last time you helped me a lot and i'm very much grateful to you.

This time i've the following problems, pls help to solve this problems.

Thanks in advance.

Problem#1
Mandatory fields of a "Data Entry UserForm" should be filled serially.
=================================

I've a data entry user form of the following:

TextBox1 = Mandatory field
TextBox2 = Optional
TextBox3 = Mandatory field
TextBox4 = Mandatory field
ComboBox1 = Mandatory field
TextBox5 = Mandatory field
ComboBox1 = Mandatory field

I want that the user must fill the mandatory fields serially (i.e; first textbox1 then textbox3 then textbox4...something like that.), o/wise user can't add any data to the worksheet.

Problem#2

I've 8 (eight) worksheets under a workbook and when i add data in a worksheet by a "data entry form",
it will copy the same data to all other worksheets at the same time.
 
Upvote 0
As this is a totally different question, you need to start a new thread. Thanks
 
Upvote 0

Forum statistics

Threads
1,213,486
Messages
6,113,932
Members
448,533
Latest member
thietbibeboiwasaco

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