in

Create a rule to Automatically open PDF attachments in Outlook

I have a user that would like to have her PDF attachments open automatically when they are received.
Movie Stars

Solution: Create a rule to Automatically open PDF attachments in Outlook

I understand.  The code below will open every pdf file received.  Follow these instructions to use this.

  1. Start Outlook 
  2. Click Tools->Macro->Visual Basic Editor 
  3. If not already expanded, expand Microsoft Outlook Objects in the Project pane, then click on Module1 
  4. Copy the code below 
  5. Paste the script into the right-hand pane of the VB Editor 
  6. Click the diskette icon on the toolbar to save the changes 
  7. Close the VB Editor 
  8. Click Tools->Macro->Security 
  9. Set Security Level to Medium 
  10. Close Outlook 
  11. Start Outlook 
  12. Create a rule that processes all messages 
  13. Set the rule's action to run a script a choose this script 

That should do it.  Every message that comes in will trigger the rule.  The rule runs the code which checks for attachments and opens any pdf files on screen.

Glad you liked the other script.  Hope this one helps out.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
Private Declare Function ShellExecute Lib "shell32.dll" _
  Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
  ByVal lpFile As String, ByVal lpParameters As String, _
  ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
 
Public Sub OpenAcrobat(Item As Outlook.MailItem)
    Dim objFSO As Object, _
        objTempFolder As Object, _
        olkAttachment As Outlook.Attachment
 
    'On Error Resume Next
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTempFolder = objFSO.GetSpecialFolder(2)
    For Each olkAttachment In Item.Attachments
        If LCase(objFSO.GetExtensionName(olkAttachment.FileName)) = "pdf" Then
            olkAttachment.SaveAsFile objTempFolder & "\" & olkAttachment.FileName
            ShellExecute 0&, "open", objTempFolder & "\" & olkAttachment.FileName, 0&, 0&, 0&
        End If
    Next
    Set olkAttachment = Nothing
    Set objTempFolder = Nothing
    Set objFSO = Nothing
End Sub