Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Easy VB task - password add to PDF file in Outlook

Posted on 2011-02-17
14
Medium Priority
?
763 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 1336 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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 1336 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 664 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
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…

604 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