Solved

Easy VB task - password add to PDF file in Outlook

Posted on 2011-02-17
14
755 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

Increase your protection from Zero Day threats!

Running two Antivirus' is never a good idea.
Taking advantage of Multiple Security layers on the other hand can often save your hide.
See which top notch security software brands have been proven to happily coexist together.
Reduce your chances of becoming a statistic.

Question has a verified solution.

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

Suggested Solutions

When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

738 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