Jump to content
News Ticker
  • Welcome to the Community
  • Use the forum to troubleshoot your Excel & VBA Problems
  • We will be launching a new website soon! www.ExcelWTF.com/Learn ! Join us to learn VBA from the ground up!
  • 0
Sign in to follow this  
Sapron75

Create general password protected pdf file

Question

Hi, I'm busy with converting excel files to pdf and send them out with Outlook. The converting is okay, but I want to add a password protection. The password will be a general one, so it doesn't have to put in manually each time the excel file will be converted. Can you help me with this. This is a part of the vba code :

 

If .Range("F2").Value = "PDF" Then
FileName = ThisWorkbook.Path & "\" & .Range("C" & CustRow).Value & " " & .Range("G" & CustRow).Value & ".pdf" 'creeert file met persnr en achternaam
WordDoc.ExportAsFixedFormat OutputFileName:=FileName, ExportFormat:=wdExportFormatPDF
WordDoc.Close False
Else 'Als het in Word moet
FileName = ThisWorkbook.Path & "\" & .Range("C" & CustRow).Value & " " & .Range("G" & CustRow).Value & ".docx"
WordDoc.SaveAs FileName


End If
If .Range("J2").Value = "Email" Then
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.Createitem(0)
With OutMail
.To = Blad16.Range("U" & CustRow).Value
.Subject = "Beste " & Blad16.Range("E" & CustRow).Value & "ADV en ziek"
.Body = "Beste " & Blad16.Range("E" & CustRow).Value & "Hier de brief mbt adv en ziek"
.Attachments.Add FileName
.Display 'Als je zonder van tevoren wilt zien dan .Display to.Send
End With

Else:
WordDoc.PrintOut
WordDoc.Close
End If
Kill (FileName) 'Gooit de pdf of word document weg wat je hebt aangemaakt

Can you help me with this one ?

 

Thanks

Ron

  • Like 1

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Hi Ron,

 

Thanks for the question. Your code looks good so far! 

 

In terms of setting a PDF password, you need to have either the Full Adoble Suite (not just the reader) or be able to install some third party PDF creators. 

 

I have seen this used a few times: http://www.pdfforge.org/pdfcreator

 

You would setup a default password using the software and then print your file to the PDF creator. More information available here:

https://www.exceltrainingvideos.com/tag/how-to-create-password-protected-pdf-file-with-vba/

 

Let me know if this helps. I can write some modified code for you once you confirm you are able to install software (not sure if you're doing this on a restricted network or not)

 

Caleeco

Share this post


Link to post
Share on other sites
  • 0
14 hours ago, Caleeco said:

Hi Ron,

 

Thanks for the question. Your code looks good so far! 

 

In terms of setting a PDF password, you need to have either the Full Adoble Suite (not just the reader) or be able to install some third party PDF creators. 

 

I have seen this used a few times: http://www.pdfforge.org/pdfcreator

 

You would setup a default password using the software and then print your file to the PDF creator. More information available here:

https://www.exceltrainingvideos.com/tag/how-to-create-password-protected-pdf-file-with-vba/

 

Let me know if this helps. I can write some modified code for you once you confirm you are able to install software (not sure if you're doing this on a restricted network or not)

 

Caleeco

Hi Caleeco,

 

Thank you for your answer. Unfortunately  I am , indeed, working on a restricted network which doesn't allow us to install third party software. I think I have to go to another solution, but not sure what I can do. The main goal is to send something to someone so that no one can read it unless they are supposed to. That's why I thought I could make a password protected pdf ... Do you have any other suggestions ?

 

Thanks

Ron

Share this post


Link to post
Share on other sites
  • 0

Ah ok, I thought that may have been the case. 

 

Can you not instead just send a copy of the Excel sheet which is password protected? You could duplicate the sheet, paste everything as values and then set a password & email it to the recipient. 

 

Let me know if this solution would suffice?

 

Caleeco

Share this post


Link to post
Share on other sites
  • 0

Hi Caleeco,

 

thank you for your answer. That wouldn't be an option, because the recipient can alter the data afterwards in excel and that's just the issue. For audit purposes the data must be data which can not be altered afterwards.  So we will leave it like it is..no password thusfar, thank you for your input though !!

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×