PDA

View Full Version : Save attachment automatically



arrun
09-20-2012, 08:49 AM
Dear all, I need a help from you folks.

Each day I get a mail at a specified time with a attachment. I need to do something such that as soon as this mail comes into my inbox, same should be saved in a specified folder in my hard disk, automatically.

Can somebody help me on how to do this?

Thanks for your help.

nickj
09-26-2012, 06:11 AM
Add this code as a new module in vba:

Public Sub saveattachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "c:\temp\"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
Set objAtt = Nothing
Next
End Sub

create a folder in the C:\ drive called temp

To call this code set up a new mail rule set your rules then select script and save attachment to disk should be visable select this save and you are done!

BrianMH
09-26-2012, 06:22 AM
You may also find the thread linked here helpful.

http://www.vbaexpress.com/forum/showthread.php?t=43276

nickj
10-04-2012, 07:14 AM
Hi Wondering if anyone can help me?

Im a newbie when it comes to programming, after extensive research on the subject ive come up with a few bits of code. I was wondering if there is someone out there to help me get this to work!

Basically what i want to do is set up a outlook rule that saves pdf attachments as they come into my inbox, but before saving them perform ocr on them as they are image pdf's. Then save the now text readable pdf using the words found within the file between Purchase Order: and Job Number: as the filename.

I realise modi does not support pdf as its a microsoft addon but i can open pdf's manually in modi so im guesing this can be automated aswell?

I've used this code to successfully save image pdf files to a folder based on a outlook rule:

Public Sub saveattachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "c:\temp\"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
Set objAtt = Nothing
Next
End Sub

This next snippet of code is supposed to run ocr using modi:

Function GetOCRText(TheFile As String) As String
On Error GoTo PROC_ERR
If TheFile = "" Then Exit Function
Dim MyDoc As Object ' MODI.document
Dim MyLayout As Object ' MODI.Layout
Set MyDoc = CreateObject("MODI.document") ' New MODI.document
MyDoc.Create TheFile
MyDoc.Images(0).OCR
Set MyLayout = MyDoc.Images(0).Layout
For Each TheWord In MyLayout.Words
Result = Result & " " & TheWord.Text
Next TheWord
Result = Result & vbCrLf & vbCrLf
GetOCRText = Result
Set MyLayout = Nothing
MyDoc.Close False
Set MyDoc = Nothing
PROC_ERR:
End Function

Please could someone point me in the right direction or give me some code to work with.

Many Thanks