Solved

Easy VB task - password add to PDF file in Outlook

Posted on 2011-02-17
14
748 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Find out what you should include to make the best professional email signature for your organization.
This video Micro Tutorial is the second in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles a…
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now