Solved

Easy VB task - password add to PDF file in Outlook

Posted on 2011-02-17
14
753 Views
Last Modified: 2012-05-11
Points awarded to anyone who can tell me how I can automate a task (maybe through Excel VB button in Outlook?) which adds a predefined password to an email which has a PDF attachment to it?

The rationale behind this, is that I receive regular PDFs, which I need to add a password to and then send to another department.  I am trying to avoid the need to save the file, open, add password via my Acrobat writer, save and then attach to email again.

Anyone who can write me a VB script to do this will be award the points.  Thanks.
0
Comment
Question by:hedgeselect
  • 4
  • 4
  • 3
  • +1
14 Comments
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 334 total points
ID: 35042168
>>> Easy VB task - password add to PDF file in Outlook

Well it's not as easy as it sounds :)

I have interacted with Adobe to some extent but couldn't find a property of "AcroPDDoc" where you could open and save the file with a password. Here is a sample to open the file but after that there is no inbuilt property where you can save the password.

Sub Sample()
    Dim AVDoc As Acrobat.AcroAVDoc
    Dim PDoc As Acrobat.AcroPDDoc
    Dim Ret As Integer
    
    Set AVDoc = CreateObject("AcroExch.AVDoc")
    
    Ret = AVDoc.Open("C:\MyFile.pdf")
    
    If ret <> -1 Then
        MsgBox ("Failed to open PDF document")
        Exit Sub
    End If
    
    Set PDoc = AVDoc.GetPDDoc
End Sub

Open in new window


There are many thoughts which are racing through my head right now. I will address them one by one

Logic 1

1) Use VBA code to extract the attachment and save it to a folder.
2) Zip the PDF file with a password and attach it to an email
3) Send email
4) Delete zip file from temp folder

Logic 2

1) Use VBA code to extract the attachment and save it to a folder.
2) Open the PDF file like the way I mentioned in the code above.
3) Use API's/Sendkeys to stimulate the clicks and then store the password. Save and Close File
4) Attach it to an email
5) Send email
6) Delete pdf file from temp folder

Logic 3 (Unsure about this)

Maybe Adobe SDK has some facility to open and protect the pdf files?

These 3 logic can be explored further but yes what you want is not an easy task (And it is not impossible either)

Sid
0
 

Author Comment

by:hedgeselect
ID: 35173219
Hi

Sorry for the delay.  I'm not a programmer so I wont know how to implement the above.  My guess by the lack of responses here, is that it cannot be done easily.
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35174162
>>>>My guess by the lack of responses here, is that it cannot be done easily.

Yes you are right. It is not that easy. Impossible... No. Just time consuming and lots of code.

The easiest is Logic 1 mentioned above. Do you think that would help?

Sid
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:hedgeselect
ID: 35174925
Does logic 1 relate to that code you pasted above? What does that code do?
0
 
LVL 30

Assisted Solution

by:SiddharthRout
SiddharthRout earned 334 total points
ID: 35175180
>>>Does logic 1 relate to that code you pasted above?

No it doesn't.

>>>What does that code do?

That code simply shows you how to open a pdf file from vba but after that there is there is no inbuilt property where you can save the password.

Logic1 is the simplest way to achieve what you want. It doesn't password protect the pdf but it zips the pdf with a password and attaches it back to the email.

Sid
0
 
LVL 29

Assisted Solution

by:leonstryker
leonstryker earned 166 total points
ID: 35214816
Having recently researched the subject of adding a password to PDF, I can say that there is no way to do it easily. There are three possible solutions:

1. Third party tool such as PDF Toolkit and a shell command. (http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/)

2. I saw C# and JavaScript examples on the web. If you are interested, I can try to find them again.

3. Don't password protect the PDF file, but rather zip it, and passwrd protect the zip. (as SiddharthRout mentions above)

Leon
0
 
LVL 42

Expert Comment

by:dlmille
ID: 35304157
What do you think about using SendKeys as part of the process to set passwords?

Dave
0
 

Author Closing Comment

by:hedgeselect
ID: 35304949
im going to drop the question, no easy solution.  thx anyway.

Not sure what sendkeys is.
0
 
LVL 42

Expert Comment

by:dlmille
ID: 35304956
SendKeys uses keystrokes to do things that there are no methods built around.

For example, to set passwords in the VBA Project Editor, one would need sendkeys to deliver the password in the right "box".

So, theoretically, one could focus on the PDF and "Send" the keys to get the right menu up for password protection and then "Send" in the password.

Doable

Dave
0
 

Author Comment

by:hedgeselect
ID: 35304991
does sendkeys require software?
0
 
LVL 42

Expert Comment

by:dlmille
ID: 35306916
SendKeys can be called from VBA - no additional software other than what you already have.
0
 
LVL 42

Expert Comment

by:dlmille
ID: 35306942
There are SOME applications that won't take SendKeys from VBA (e.g., like RDP - Remote Desktop), so a quick test against PDF would testify whether this route is worth further exploration.

To see how "easy" it is from VBA - here's a related link using sendkeys to PDF (but not the password):  http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_22095210.html

Dave
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question