|
Our company receives a large number of PDF documents from a customer and I'm writing the necessary code to automate the conversion and importing of that document into our Unidata database, running on Linux.
Right now it's a two-step process for the user:
1. Open the email in Outlook, right-click the PDF attachment, save-as in a predefined location and file name.
2. In Unidata, run my program that copies that raw PDF file from the user's PC to Linux, run that file through the Linux program pdftotext, scrape that text file for the necessary data and produce the respective order information into our backend system.
I'd REALLY like to make this a one-step process. In other words, I'd like to run (some version of) my Outlook script from Accuterm so the user only has to have the email 'selected' in outlook, then run my program that will do both of those steps in one command.
Following is the Outlook script that I'd like to create and run from Accuterm. I'm not fluent in vBasic but I'm trying to get that way. Any help would be appreciated.
Option Explicit
Public Sub SaveAttachments() Dim objOL As Outlook.Application Dim objMsg As Outlook.MailItem 'Object Dim objAttachments As Outlook.Attachments Dim objSelection As Outlook.Selection Dim i As Long Dim lngCount As Long Dim strFile As String Dim strFolderpath As String Dim strDeletedFiles As String
strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16) On Error Resume Next
Set objOL = CreateObject("Outlook.Application")
Set objSelection = objOL.ActiveExplorer.Selection
strFolderpath = "c:\hubbard\"
For Each objMsg In objSelection
Set objAttachments = objMsg.Attachments lngCount = objAttachments.Count strDeletedFiles = ""
If lngCount > 0 Then For i = lngCount To 1 Step -1
strFile = objAttachments.Item(i).FileName strFile = "gmsaporder.pdf"
strFile = strFolderpath & strFile
objAttachments.Item(i).SaveAsFile strFile
If objMsg.BodyFormat <> olFormatHTML Then strDeletedFiles = strDeletedFiles & vbCrLf & "<file://" & strFile & ">" Else strDeletedFiles = strDeletedFiles & "<br>" & "<a href='file://" & _ strFile & "'>" & strFile & "</a>" End If
MsgBox objAttachments.Item(i) & " has been saved to your PC. Proceed to Prelude and import it now." Next i
If objMsg.BodyFormat <> olFormatHTML Then objMsg.Body = vbCrLf & "The file(s) were saved to " & strDeletedFiles & vbCrLf & objMsg.Body Else objMsg.HTMLBody = "<p>" & "The file(s) were saved to " & strDeletedFiles & "</p>" & objMsg.HTMLBody End If objMsg.Save End If Next
ExitSub:
Set objAttachments = Nothing Set objMsg = Nothing Set objSelection = Nothing Set objOL = Nothing End Sub
p.s. the above script was shamelessly copied from a website somewhere on the web. I lay no claim to an intimate knowledge of vBasic or this script in particular. I was able to understand it enough to make the changes I needed to get the file to be located and named exactly as I needed it to. However I fail to have the skills it takes to translate this into a script that can be execute utilizing the Accuterm toolset for executing said scripts.
------------- Dave Laansma
|