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.
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
Copy link to clipboard
Copied
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).