Solved

Easy VB task - password add to PDF file in Outlook

Posted on 2011-02-17
14
744 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
 

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 41

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 41

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 41

Expert Comment

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you don't know how to downgrade, my instructions below should be helpful.
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now