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.
I wish anyone could suggest on how to do it. Thank you so much everyone.
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.