PDA

View Full Version : Export excel to pdf with pass



chien_bap
11-15-2016, 09:36 PM
Dear All,

I have code in VBA which can export worksheet to pdf file. But i can't set password for file pdf. So i need help from all of you to solve it.

Thank you so much

Kenneth Hobs
11-16-2016, 06:29 AM
Welcome to the forum!

You will need a 3rd party program/application to add a password to a pdf file. e.g. Acrobat (not the Reader), PDFcreator, PDFtk, PDFfill, PDFsam, etc.

The first two programs have objects which takes some effort to code but usually works out well. The others usually have command shell options that can be automated by building the strings to send to the command shell.

If you don't do it a lot, I would just use the program's GUI to do it manually. If you want to do it in VBA, we would need to know what program you will use and what version and particularly so for PDFcreator as its object's methods changed significantly.

chien_bap
11-16-2016, 08:00 PM
Welcome to the forum!

You will need a 3rd party program/application to add a password to a pdf file. e.g. Acrobat (not the Reader), PDFcreator, PDFtk, PDFfill, PDFsam, etc.

The first two programs have objects which takes some effort to code but usually works out well. The others usually have command shell options that can be automated by building the strings to send to the command shell.

If you don't do it a lot, I would just use the program's GUI to do it manually. If you want to do it in VBA, we would need to know what program you will use and what version and particularly so for PDFcreator as its object's methods changed significantly.

Hi Mr Kenneth

I'm using PDFtk tool, but i can't run it on VBA when i'm running code. Please help me with my attach file below.

Many many thanks to you. Please help me

Kenneth Hobs
11-16-2016, 08:31 PM
Why can't you run it? It is a simple Shell().

It should be something along the lines of what I posted here. If needed, I can install it and make sure.
http://www.vbaexpress.com/forum/showthread.php?35164-Generate-Create-PDF-using-VBA-and-Password-protect-PDF

chien_bap
11-16-2016, 09:51 PM
Dear Mr Kenneth,

I don't know the reason why my code not work. I have installed pdftk and pdftk serve too.

when I used Sheel()... it not export the pdf output file. there is nothing in my output folder. I had captured my error on VBA code here. I hope you can help me to fix it. Please...

Here are my error when running code on VBA:
17628

17629

GTO
11-17-2016, 12:49 AM
Greetings:

You need to define/declare 'cmdStr', preferably at the start of the Sub Procedure. Something like:



Sub GuiMail()
Dim OutApp As Object, OutMail As Object
Dim WB As Workbook, Ash As Worksheet, Ash1 As Worksheet, mailAddress As String, i As Integer, ir As Integer
Dim Rcount As Long, FileName As String, Rnum As Long, strHeader As String, strRow As String, fTemp As String, Pwd As String
Dim cmdStr As String


Application.ScreenUpdating = False
Application.DisplayAlerts = False

' Remainder of your code...

End Sub


Notice the "Option Explicit" at the top of the editing window? This is a good idea to include (as you have) as it requires all variables to be declared. Thus, as 'cmdStr' was not declared, the error kicked up.

Hope that helps,

Mark