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
Solved

Create a Rule to Open, Print & Exit PDF File in Outlook 2007

Posted on 2008-10-30
11
277 Views
Last Modified: 2010-05-18
i used the code from this question, and it works fine, but i need it to close adobe.
http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_23601804.html

i added this to print the pdf
ShellExecute 0&, "print", objTempFolder & "\" & olkAttachment.FileName, 0&, 0&, 0&

but now i need to exit adobe after it prints. how do i do that?

or is there an easier way?
all i want to to is this
when a email comes in with Bizhub in sender address, open the pdf, print it, then exit adobe program.

0
Comment
Question by:bignadad
  • 6
  • 4
11 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 22847151
Hi, bignadad.

You can use something like this to terminate Acrobat when the printing is finished.
http://www.eggheadcafe.com/community/aspnet/8/20934/kill-process-using-visual.aspx
0
 
LVL 2

Author Comment

by:bignadad
ID: 22849334
how do i configure that code for adobe acrobat?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 22849434
The code doesn't have to be configured.  It just needs to be used.  Add the code to waht you already have in Outlook, then call it per the example on the page.  The command for killing Acrobat Reader is

    KillProcess "acrord32"

acrord32 is the name of the Acrobat executable which can be found by opening Windows Task Manager and looking through the list of processes.

If you're using a different version of Acrobat, e.g. Acrobat Pro, then I don't have Acrobat Pro so I don't know if the executable has the same name or not.

There's a type on this line of the code from that page

serviceame = LCase(Trim(CStr(oService.Name) & ""))

"serviceame" should be "servicename", i.e. the n is missing.  You'll want to fix that.
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.

 
LVL 2

Author Comment

by:bignadad
ID: 22850154
i added that code and the process and nothing happens. its like it closes it before it has time to open or print.
On Error GoTo ErrHandler
         
         Dim oWMI
         Dim ret
         Dim sService
         Dim oWMIServices
         Dim oWMIService
         Dim oServices
         Dim oService
         Dim servicename
         
          Set oWMI = GetObject("winmgmts:")
          Set oServices = oWMI.InstancesOf("win32_process")
 
          For Each oService In oServices
                 
                 servicename = LCase(Trim(CStr(oService.Name) & ""))
                 
                 If InStr(1, servicename, LCase(processName), vbTextCompare) > 0 Then
                    ret = oService.Terminate
                 End If
 
          Next
          
          Set oServices = Nothing
          Set oWMI = Nothing
 
ErrHandler:
  Err.Clear
End Sub
 
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&
            ShellExecute 0&, "print", objTempFolder & "\" & olkAttachment.FileName, 0&, 0&, 0&
            KillProcess "acrobat"
        End If
    Next
    Set olkAttachment = Nothing
    Set objTempFolder = Nothing
    Set objFSO = Nothing
End Sub

Open in new window

0
 
LVL 76

Expert Comment

by:David Lee
ID: 22850236
Hmmm, I was thinking that ShellExecute paused execution until printing was finished.  Now that you mention this problem I remember that it doesn't.  Let me think about it a bit.
0
 
LVL 2

Author Comment

by:bignadad
ID: 22853697
is there not a pause i can insert into the code between the print and exit
0
 
LVL 2

Author Comment

by:bignadad
ID: 22880605
Is there nothing i can do to close the program?
0
 
LVL 23

Expert Comment

by:debuggerau
ID: 22927092
why not just put a wait timer in? Say One Minute...
0
 
LVL 2

Author Comment

by:bignadad
ID: 22927338
how could i do that?
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 22933573
Apologies for being so slow to post.  The problem is that a timer or a pause won't work because you have no idea when Acrobat will finish printing.  Too short a time and the next command will kill Acrobat while it's still processing.  Too long a time and Outlook will be tied up unnecessarily.  The solution needs to know when Acrobat finishes so the closing is appropriately timed.   Adobe's documentation says that the /T switch will close the Acrobat after printing.  Sadly, that appears to be false, at least for version 8.  I found this page which documents the problem and offers a solution.  I haven't tested this, so I don't know that it works.

http://www.biopdf.com/acrowrap/close_adobe_reader.php
0
 
LVL 2

Author Comment

by:bignadad
ID: 22935254
thanks. looks pretty good. i will try tomorrow.
0

Featured Post

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.

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
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.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
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 …

828 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