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
 

Atiqul Haque

New Member
Joined
Dec 13, 2020
Messages
45
Office Version
  1. 2016
Platform
  1. Windows
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.
 

Some videos you may like

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,318
Office Version
  1. 365
Platform
  1. Windows
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.
 

Atiqul Haque

New Member
Joined
Dec 13, 2020
Messages
45
Office Version
  1. 2016
Platform
  1. Windows
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?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,318
Office Version
  1. 365
Platform
  1. Windows
You can use Ctrl P to print the sheet when using the recorder.
 

Atiqul Haque

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

ADVERTISEMENT

But
You can use Ctrl P to print the sheet when using the recorder.
as i use code to prevent printing in the workbook it also not worked!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,318
Office Version
  1. 365
Platform
  1. Windows
Then disable the code first.
 

Atiqul Haque

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

ADVERTISEMENT

Then disable the code first.
Thank you very much.
It's not working. Anyway it's ok. Thank you very much for your support.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,318
Office Version
  1. 365
Platform
  1. Windows
Glad to help & thanks for the feedback.
 

Atiqul Haque

New Member
Joined
Dec 13, 2020
Messages
45
Office Version
  1. 2016
Platform
  1. Windows
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,318
Office Version
  1. 365
Platform
  1. Windows
As this is a totally different question, you need to start a new thread. Thanks
 

Watch MrExcel Video

Forum statistics

Threads
1,127,133
Messages
5,622,911
Members
415,938
Latest member
Walkie1994

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
Top