简体   繁体   中英

VBA: How to password protect PDF from Excel

I currently use the following code to output part of the Excel worksheet as PDF. I am wondering if it would be possible to also add a password to the PDF output.

Sub print_pdf()

Sheets(Array("Sheet1", "Sheet2")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & NameOfWorkbook _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True

End Sub

A quick google shows me this thread: https://answers.microsoft.com/en-us/msoffice/forum/msoffice_word-mso_win10/save-password-protected-pdf-file-with-vba/e3b0be70-d7a5-421b-888f-980d35386c40

Where a user states "the Office PDF option does not include an option for password protection.", and suggests a third-party alternative, such as http://download.pdfforge.org/ (I've never used it, but the last post in the attached thread claims to have a working script).

Admittedly, the thread is about 2 years old, so it may be out of date, but I would suggest you try pdfforge or some other third party alternative.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM