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

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Status
Not open for further replies.

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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