• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

VBA code to create PDF using AdobePDFMakerforOffice with Encription

New Here ,
Jun 24, 2022 Jun 24, 2022

Copy link to clipboard

Copied

Hi I have VBA code to conevrt the excel file into PDF. But i just want to add the encription password to the pdf. But i don't how to do the in VBA. Can u pls help me for the same.

TOPICS
Create PDFs , Edit and convert PDFs , Print and prepress

Views

2.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 24, 2022 Jun 24, 2022

Copy link to clipboard

Copied

Here is the code what i have.

 


' ----------------------------------------------------
' ConvertFStoAdobePDFWithLinks - convert the FS
' to a PDF file, in the Desktop folder as the document
' ----------------------------------------------------
Sub ConvertFStoAdobePDFWithLinks()

Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False

Dim pdfname, i, a
Dim pmkr As AdobePDFMakerForOffice.PDFMaker
Dim stng As AdobePDFMakerForOffice.ISettings
If Not ActiveWorkbook.Saved Then
MsgBox "You must save the document before converting it to PDF", vbOKOnly, ""
Exit Sub
End If
Set pmkr = Nothing ' locate PDFMaker object
For Each a In Application.COMAddIns
If InStr(UCase(a.Description), "PDFMAKER") > 0 Then
Set pmkr = a.Object
Exit For
End If
Next
If pmkr Is Nothing Then
Call NormalPDFPrint
Exit Sub
End If
pdfname = Environ("USERPROFILE") & "\Desktop\" & ActiveWorkbook.Name ' construct output name
i = InStrRev(pdfname, ".")
pdfname = IIf(i = 0, pdfname, Left(pdfname, i - 1)) & ".pdf"
' delete PDF file if it exists
If Dir(pdfname) <> "" Then Kill pdfname
pmkr.GetCurrentConversionSettings stng
stng.AddBookmarks = True
stng.AddLinks = True
stng.AddTags = False
stng.ConvertAllPages = True
stng.FitToOnePage = False
stng.CreateFootnoteLinks = True
stng.CreateXrefLinks = True
stng.OutputPDFFileName = pdfname
stng.PromptForPDFFilename = False
stng.ShouldShowProgressDialog = True
stng.ViewPDFFile = True
pmkr.CreatePDFEx stng, 0 ' perform conversion
If Dir(pdfname) = "" Then ' see if conversion failed
MsgBox "Could not create requested PDF file", vbOKOnly, "Print failed"
Else
'MsgBox "PDF file generated with the name" & vbNewLine & vbNewLine & ActiveWorkbook.Name & vbNewLine & vbNewLine & "And Saved in your Desktop Folder", vbOKOnly
End If

Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 24, 2022 Jun 24, 2022

Copy link to clipboard

Copied

LATEST

PDFMaker for Office is not a supported or documented programmer's interface; it's there for the internal workings of PDFMaker. The Acrobat SDK lists supported interfaces (with nothing like what you want). 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines