Consulting

Results 1 to 4 of 4

Thread: Save attachment automatically

  1. #1

    Save attachment automatically

    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.

  2. #2
    VBAX Regular
    Joined
    Sep 2012
    Posts
    8
    Location
    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!

  3. #3
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    You may also find the thread linked here helpful.

    http://www.vbaexpress.com/forum/showthread.php?t=43276
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

  4. #4
    VBAX Regular
    Joined
    Sep 2012
    Posts
    8
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •