Hey Charlize, thank you so much for your feedback I'm wanting to use this piece of code:
[VBA] Public Sub saveattachtoDisk(itm As Outlook.MailItem)
'attachment
Dim objAtt As Outlook.Attachment 'number of attachments
Dim Attcount As Long
'savefolder
Dim saveFolder As String
saveFolder = "c:\temp\"
'if no attachments, skip
If itm.Attachments.Count <> 0 Then
'loop through attachments
For Attcount = 1 To itm.Attachments.Count
Set objAtt = itm.Attachments.item(Attcount)
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
Set objAtt = Nothing
Next Attcount
End If
End Sub
[/VBA]
With this piece of code, so they work together:
[VBA]
Sub Test()
Dim purchaseOrderFileName As String
purchaseOrderFileName = Get_Purchase_Order("c:\folder1\folder2\attachment.pdf")
End Sub
Function Get_Purchase_Order(fileName As String) As String
Dim MDoc As MODI.Document
Dim MLayout As MODI.Layout
Dim MWord As MODI.Word
Dim OCRtext As String
Dim p1 As Long, p2 As Long
Set MDoc = New MODI.Document
MDoc.Create fileName
MDoc.Images(0).OCR
Set MLayout = MDoc.Images(0).Layout
OCRtext = ""
For Each MWord In MLayout.Words
OCRtext = OCRtext & " " & MWord.Text
Next
MDoc.Close False
Get_Purchase_Order = ""
p1 = InStr(OCRtext, "Purchase Order:")
If p1 > 0 Then
p1 = p1 + Len("Purchase Order:")
p2 = InStr(p1, OCRtext, "Job Number:")
If p2 > 0 Then Get_Purchase_Order = Mid(OCRtext, p1, p2 - p1)
End If
Set MLayout = Nothing
Set MDoc = Nothing
End Function
[/VBA]
How can I get these two pieces of code to work with one another? I'm a programming newbie, so you probally laughing at me right now :P
Basically in a nut shell what im trying to achieve is saving a pdf attachment from outlook into a folder, then doing ocr on the saved image pdf file using modi (microsoft office document imaging) and then saving the now text readable pdf with a file name extracted from within the string of the file between the words Purchase Order: and Job No: calling the macro from within outlook using a script mailing rule. If you need a template of the image pdf file I can provide it.
Any help or pointers would be great.
Many Thanks
Nick