Write-Protect an excel generated PDF: How to do it?

Status
Not open for further replies.

poizones

New Member
Joined
Mar 30, 2018
Messages
7
Can anyone suggest on how to write-protect a PDF generated from excel using VBA? I have been using the following code for almost two years already buy due to security reason, I need to add write-protection to this code.

Code:
Sub SavePDF()

Dim sRange1 As String
Dim sRange2 As String
Dim sPace As String
Dim rngRange As Range
Dim strFilename, strDirname, strPathname, strDefpath As String
 On Error Resume Next

sRange1 = ActiveSheet.Range("F9")
sRange2 = ActiveSheet.Range("Z13")
sPace = (" DTR ")

strDirname = sRange1 + sPace + sRange2

Set rngRange = Worksheets("DTR").Range("C6")

strFilename = rngRange.Value & Format(Now(), " mmddyyyy")
strDefpath = Application.ActiveWorkbook.Path

If IsEmpty(strDirname) Then Exit Sub
If IsEmpty(strFilename) Then Exit Sub
If rngRange.Value <= "" Then Exit Sub

MkDir strDefpath & "\" & strDirname
strPathname = strFilename
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strDefpath & "\" & strDirname & "\" & strFilename & ".pdf" _
    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
    :=False, OpenAfterPublish:=False2
    
End Sub

I wish anyone could suggest on how to do it. Thank you so much everyone.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Status
Not open for further replies.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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