Results 1 to 30 of 30

Thread: [RESOLVED] Outlook 2007 - How to save Email Attachments to Local Disc

  1. #1

    Thread Starter
    Member Mr.Cool's Avatar
    Join Date
    Feb 2010
    Posts
    35

    Resolved [RESOLVED] Outlook 2007 - How to save Email Attachments to Local Disc

    Hi All,

    I want to save the attachments of Email (Sent with a particular Subject Line), to my local machine. Can someone please tell me the way to do this.

    My attachment may contain any type of file.

    Regards,
    Mr.Cool

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Welcome to the forums

    Here are few links to achieve what you want. Understand the code and then amend it as per your needs. If you get stuck, simply post the code that you tried and we will definitely help you

    http://www.vbaexpress.com/kb/getarticle.php?kb_id=522
    http://www.outlookcode.com/codedetail.aspx?id=70
    http://www.outlookcode.com/codedetail.aspx?id=1494
    http://www.outlook-tips.net/code/saveatt.htm
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Member Mr.Cool's Avatar
    Join Date
    Feb 2010
    Posts
    35

    Lightbulb Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Thanks SID.

    I will try that.

  4. #4

    Thread Starter
    Member Mr.Cool's Avatar
    Join Date
    Feb 2010
    Posts
    35

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Okey, I stuck once again.

    I used following code which is saving attachments for selected records:

    vb Code:
    1. Public Sub SaveAttachments()
    2. Dim objOL As Outlook.Application
    3. Dim objMsg As Outlook.MailItem 'Object
    4. Dim objAttachments As Outlook.Attachments
    5. Dim objSelection As Outlook.Selection
    6. Dim i As Long
    7. Dim lngCount As Long
    8. Dim strFile As String
    9. Dim strFolderpath As String
    10. Dim strDeletedFiles As String
    11.  
    12.     strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
    13.     Set objOL = CreateObject("Outlook.Application")
    14.     Set objSelection = objOL.ActiveExplorer.Selection
    15.     strFolderpath = strFolderpath & "\OLAttachments\"
    16.     MsgBox strFolderpath
    17.     For Each objMsg In objSelection
    18.     Set objAttachments = objMsg.Attachments
    19.     lngCount = objAttachments.Count
    20.        If lngCount > 0 Then
    21.        For i = lngCount To 1 Step -1
    22.     strFile = objAttachments.Item(i).FileName
    23.         strFile = strFolderpath & strFile
    24.         objAttachments.Item(i).SaveAsFile strFile
    25.      
    26.     If objMsg.BodyFormat <> olFormatHTML Then
    27.         strDeletedFiles = strDeletedFiles & vbCrLf & "<file://" & strFile & ">"
    28.         Else
    29.         strDeletedFiles = strDeletedFiles & "<br>" & "<a href='file://" & _
    30.         strFile & "'>" & strFile & "</a>"
    31.     End If
    32.         MsgBox strDeletedFiles
    33.         Next i
    34.     End If
    35.         If objMsg.BodyFormat <> olFormatHTML Then
    36.         objMsg.Body = objMsg.Body & vbCrLf & _
    37.         "The file(s) were saved to " & strDeletedFiles
    38.     Else
    39.         objMsg.HTMLBody = objMsg.HTMLBody & "<p>" & _
    40.         "The file(s) were saved to " & strDeletedFiles & "</p>"
    41.     End If
    42.         objMsg.Save
    43.     ' End If
    44.     Next
    45.     ExitSub:
    46. Set objAttachments = Nothing
    47. Set objMsg = Nothing
    48. Set objSelection = Nothing
    49. Set objOL = Nothing
    50. End Sub

    To run this rule automatically, I want to create a rule which says

    If a msg. comes with specific subject Move this to Some Folder and run the script

    The problem is that when it is showing no script names in Select Script Box.

    Please Note: I copied the code under ThisOutlookSession (Pressing Ctrl+F11 on Outlook and pasted the code on VBA window)

    How can I modify my script so that it will run on the Mails with specific subject and also how can I select the script name while creating the rule?
    Last edited by Mr.Cool; Feb 18th, 2010 at 12:33 AM.

  5. #5

    Thread Starter
    Member Mr.Cool's Avatar
    Join Date
    Feb 2010
    Posts
    35

    Exclamation Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Still No luck

    Can some one please look into this

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Use the The NewMailEx event which fires for messages arriving on any email account.

    In the NewMailEx event, check for the "specific subject" and if found, call the sub that you have written. The event is in the built-in ThisOutlookSession module in Outlook VBA.

    Hope this helps...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  7. #7

    Thread Starter
    Member Mr.Cool's Avatar
    Join Date
    Feb 2010
    Posts
    35

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Hi Sid,

    Thanks for your reply.

    I made some changes in my script and now it is working fine.

    But the problem is I am not able to create a following Rule:

    If Subject Contains OLAttach move it to folder OutlookAttach and Run Script

    When I am trying to set Script name - It is not showing even a single script to select in "Select Script" box.

    How can I get my script name displaying here????

  8. #8
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Show me the code that you are using to check the subject?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  9. #9

    Thread Starter
    Member Mr.Cool's Avatar
    Join Date
    Feb 2010
    Posts
    35

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    I am just applying a rule that If subject contains word OlAttachment then move the message to OutlookAttachment Folder (which is the subfolder of Inbox)

    After this I am just trying to run macro on the contents of OutlookAttachment folder only.

    Here is the code which I am using right now

    Code:
    Sub GetAttachments()
     
     On Error GoTo GetAttachments_err
     
     Dim ns As NameSpace
     Dim Inbox As MAPIFolder
     Dim SubFolder As MAPIFolder
     Dim Item As Object
     Dim Atmt As Attachment
     Dim FileName As String
     Dim i As Integer
     
     
     Set ns = GetNamespace("MAPI")
     Set Inbox = ns.GetDefaultFolder(olFolderInbox)
     Set SubFolder = Inbox.Folders("AutomationOutlook")
     i = 0
     
     
     
     If SubFolder.Items.Count = 0 Then
        MsgBox "There are no messages in the Inbox.", vbInformation, _
               "Nothing Found"
        Exit Sub
     End If
     
     For Each Item In SubFolder.Items
        For Each Atmt In Item.Attachments
           FileName = "C:\OutlookAttachments\" & Atmt.FileName
           Atmt.SaveAsFile FileName
           i = i + 1
        Next Atmt
     Next Item
     
     If i > 0 Then
        MsgBox "I found " & i & " attached files." _
           & vbCrLf & "I have saved them into the C:\OutlookAttachments folder." _
           & vbCrLf & vbCrLf & "Have a nice day.", vbInformation, "Finished!"
     Else
        MsgBox "I didn't find any attached files in your mail.", vbInformation, _
        "Finished!"
    End If
     
    GetAttachments_exit:
       Set Atmt = Nothing
       Set Item = Nothing
       Set ns = Nothing
       Exit Sub
       
    GetAttachments_err:
       MsgBox "An unexpected error has occurred." _
          & vbCrLf & "Please note and report the following information." _
          & vbCrLf & "Macro Name: GetAttachments" _
          & vbCrLf & "Error Number: " & Err.Number _
          & vbCrLf & "Error Description: " & Err.Description _
          , vbCritical, "Error!"
       Resume GetAttachments_exit
     
    End Sub
     
     
    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
     
    End Sub
    But I am unable to run this script automatically. I want to run macro automatically as soon as the new mail arrive.

  10. #10
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Do this...

    First paste your macro in the module.

    Then

    Click on Tools~~>Rules and Alerts
    Click on "New Rule"
    Click on "start from a blank rule"
    Select "Check messages When they arrive"
    Under conditions, click on "with specific words in the subject"
    Click on "specific words" under rules description.
    Type the word that you want to check in the dialog box that pops up and click on "add".
    Click "Ok" and click next
    select "move it to specified folder" and also select "run a script" in the same box
    In the box below, specify the specific folder and also the script (the macro that you have in module) to run.
    Click on finish.

    You are done
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  11. #11

    Thread Starter
    Member Mr.Cool's Avatar
    Join Date
    Feb 2010
    Posts
    35

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    I performed the exact steps you mentioned but in the last step when I clicked on script link (To add the script which I want to run), it opens a select script box, but this box is empty i.e. it is not diplaying any script name to select.

    What should I do so that it will display my script name (Or macro name) in select script box?

  12. #12
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Paste the macro in a module and not in the ThisOutlookSession

    To get the module, right click on the ThisOutlookSession and click on "Insert module"
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  13. #13

    Thread Starter
    Member Mr.Cool's Avatar
    Join Date
    Feb 2010
    Posts
    35

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Tried that but all efforts gone in vain.

    Still I am not able to see script Name in select script Box.

    SID Is their any other way to run this script automatically?

    I would appreciate if someone will help me in troubleshooting this Select Script Problem.

  14. #14
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Show me a screenshot of

    1) the place where you have pasted the script.
    2) the window where u need to select the script.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  15. #15

    Thread Starter
    Member Mr.Cool's Avatar
    Join Date
    Feb 2010
    Posts
    35

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Please Find the Screenshot enclosed with this mail as an attachments
    Attached Images Attached Images   
    Last edited by Mr.Cool; Feb 19th, 2010 at 04:01 AM. Reason: Attaching Files

  16. #16
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    A "run a script" rule action takes a MailItem or MeetingItem as its parameter, then uses that item in the code:

    Change your code to

    Code:
    Sub GetAttachments(MyMail As MailItem)
        '~~> Your relevant code
    End Sub
    Also click on Tools~~>Macro~~>Security and set it to low for your macro to work....
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  17. #17

    Thread Starter
    Member Mr.Cool's Avatar
    Join Date
    Feb 2010
    Posts
    35

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    SID u Rocks Man.

    Problem is solved now.

    But I got one another Problem now:

    My script is running before my mail comes to destination Folder (OutlookAutomation Folder).

    In this case I am facing following problems:

    1. If OutlookAutomation Folder is empty then It is saving No attachments (As script is running before the new mail arrives in this Folder).

    2. If already there are few mail attachments present in this folder, then it is saving attachments of old mails - but I want it to save attachment of latest arrived mail.

  18. #18
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Show me the final code that you are using.... we might need to add few conditions in that...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  19. #19

    Thread Starter
    Member Mr.Cool's Avatar
    Join Date
    Feb 2010
    Posts
    35

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Here is the final code I am using.

    vb Code:
    1. Sub GetAttachments(MyMail As MailItem)
    2.  
    3.  On Error GoTo GetAttachments_err
    4.  
    5.  Dim ns As NameSpace
    6.  Dim Inbox As MAPIFolder
    7.  Dim SubFolder As MAPIFolder
    8.  Dim Item As Object
    9.  Dim Atmt As Attachment
    10.  Dim FileName As String
    11.  Dim i As Integer
    12.  
    13.  
    14.  Set ns = GetNamespace("MAPI")
    15.  Set Inbox = ns.GetDefaultFolder(olFolderInbox)
    16.  Set SubFolder = Inbox.Folders("AutomationOutlook")
    17.  i = 0
    18.  
    19.  
    20.  
    21.  If SubFolder.Items.Count = 0 Then
    22.     MsgBox "There are no messages in the Inbox.", vbInformation, _
    23.            "Nothing Found"
    24.     Exit Sub
    25.  End If
    26.  
    27.  
    28.  For Each Item In SubFolder.Items
    29.     For Each Atmt In Item.Attachments
    30.        FileName = "C:\OutlookAttachments\" & Atmt.FileName
    31.        Atmt.SaveAsFile FileName
    32.        i = i + 1
    33.     Next Atmt
    34.  Next Item
    35.  
    36.  If i > 0 Then
    37.     MsgBox "I found " & i & " attached files." _
    38.        & vbCrLf & "I have saved them into the C:\OutlookAttachments folder." _
    39.        & vbCrLf & vbCrLf & "Have a nice day.", vbInformation, "Finished!"
    40.  Else
    41.     MsgBox "I didn't find any attached files in your mail.", vbInformation, _
    42.     "Finished!"
    43.    
    44. End If
    45.  
    46. GetAttachments_exit:
    47.    Set Atmt = Nothing
    48.    Set Item = Nothing
    49.    Set ns = Nothing
    50.    Exit Sub
    51.    
    52. GetAttachments_err:
    53.    MsgBox "An unexpected error has occurred." _
    54.       & vbCrLf & "Please note and report the following information." _
    55.       & vbCrLf & "Macro Name: GetAttachments" _
    56.       & vbCrLf & "Error Number: " & Err.Number _
    57.       & vbCrLf & "Error Description: " & Err.Description _
    58.       , vbCritical, "Error!"
    59.    Resume GetAttachments_exit
    60.  
    61. End Sub

  20. #20
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Check this for me....

    Paste this code and set the script to "Sample". Now send yourself a sample email with the relevant subject... does it run before you receive the email or after you receive it.

    Code:
    Sub Sample(MyMail As MailItem)
        Dim strID As String, olNS As Outlook.NameSpace
        Dim olMail As Outlook.MailItem
        
        strID = MyMail.EntryID
        Set olNS = Application.GetNamespace("MAPI")
        Set olMail = olNS.GetItemFromID(strID)
        
        '~~> Display the subject
        MsgBox olMail.Subject
        
        Set olMail = Nothing
        Set olNS = Nothing
    End Sub
    Also this

    For Each Item In SubFolder.Items
    is causing the code to run for all emails...

    Edit: In the meantime I will amend your code...
    Last edited by Siddharth Rout; Feb 19th, 2010 at 05:21 AM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  21. #21

    Thread Starter
    Member Mr.Cool's Avatar
    Join Date
    Feb 2010
    Posts
    35

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    How to test this?

    This script is not saving any attachments.

    So I am unable to decide whether script is running before the mail arrives in the destination folder or after that.
    Last edited by Mr.Cool; Feb 19th, 2010 at 05:28 AM.

  22. #22
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    It won't save the attachment, it will display a message.... The subject of the email... This is a test code.... If this works then I can give you a more refined code...

    Anyways... you can still try this code... It's just that I don't have access to Outlook 2007.

    Code:
    Sub Sample(MyMail As MailItem)
        Dim strID As String, olNS As Outlook.NameSpace
        Dim olMail As Outlook.MailItem
     
        strID = MyMail.EntryID
        Set olNS = Application.GetNamespace("MAPI")
        Set olMail = olNS.GetItemFromID(strID)
        
        If olMail.Attachments.Count > 0 Then
            '~~> Save the Attachement to the relevant path
            olMail.Attachments.Item.SaveAsFile "C:\OutlookAttachments\"
        Else
            '~~> Else inform the user
            MsgBox "No Atachments Found"
        End If
        
        Set olMail = Nothing
        Set olNS = Nothing
    End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  23. #23

    Thread Starter
    Member Mr.Cool's Avatar
    Join Date
    Feb 2010
    Posts
    35

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Code is throwing compilation error at following Line :

    Code:
    olMail.Attachments.Item.SaveAsFile "C:\OutlookAttachments\"
    Error shown is as follows:

    Compile Error: Argument Not Optional

  24. #24
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Since I cannot test it, test this for me...

    Code:
    Sub Sample(MyMail As MailItem)
        Dim strID As String, olNS As Outlook.NameSpace
        Dim olMail As Outlook.MailItem
     
        strID = MyMail.EntryID
        Set olNS = Application.GetNamespace("MAPI")
        Set olMail = olNS.GetItemFromID(strID)
        
        If olMail.Attachments.Count > 0 Then
            For i = 1 To olMail.Attachments.Count
                '~~> Save all the Attachement to the relevant path
                olMail.Attachments.Item(i).SaveAsFile "C:\OutlookAttachments\"
            Next
        Else
            '~~> Else inform the user
            MsgBox "No Atachments Found"
        End If
        
        Set olMail = Nothing
        Set olNS = Nothing
    End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  25. #25

    Thread Starter
    Member Mr.Cool's Avatar
    Join Date
    Feb 2010
    Posts
    35

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Thanks SID for your time.

    SID I already tried that.

    It is displaying Path error as follows:

    Cannot save the attachment. Path does not Exist. Verify the Path is correct.

    I tested by setting other path also, but still showing the same error.

  26. #26
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Try removing the last backslash \ in the path...

    Or better still try this...

    Code:
    Sub Sample(MyMail As MailItem)
        Dim strID As String, olNS As Outlook.NameSpace
        Dim olMail As Outlook.MailItem
        Dim strFileName As String
        
        strID = MyMail.EntryID
        Set olNS = Application.GetNamespace("MAPI")
        Set olMail = olNS.GetItemFromID(strID)
        
        If olMail.Attachments.Count > 0 Then
            For i = 1 To olMail.Attachments.Count
                strFileName = "C:\OutlookAttachments\" & olMail.Attachments.Item(i).FileName
                '~~> Save all the Attachement to the relevant path
                olMail.Attachments.Item(i).SaveAsFile strFileName
            Next
        Else
            '~~> Else inform the user
            MsgBox "No Atachments Found"
        End If
        
        Set olMail = Nothing
        Set olNS = Nothing
    End Sub
    Last edited by Siddharth Rout; Feb 19th, 2010 at 06:26 AM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  27. #27

    Thread Starter
    Member Mr.Cool's Avatar
    Join Date
    Feb 2010
    Posts
    35

    Resolved Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Thanks SID.

    It looks like It is working exactly the way I want it to work.

    Thanks for your help and time.

  28. #28
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Outlook 2007 - How to save Email Attachments to Local Disc

    Glad to be of help

    Do remember to mark the thread resolved by pulling down the threads menu on the top and clicking on "Mark Thread Resolved"
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  29. #29
    New Member
    Join Date
    Mar 2010
    Posts
    5

    Re: [RESOLVED] Outlook 2007 - How to save Email Attachments to Local Disc

    Thanks SID

    But I've abother problem is:

    If I applied with more than 1 rule, the other rules' attachments cannot be automatically saved!!!

    What I've done is different rule with different module, and the only difference between modules is different save path~

    I dunno why~ can you help me to check???

  30. #30
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [RESOLVED] Outlook 2007 - How to save Email Attachments to Local Disc

    Welcome to the forums

    I will be glad to help you. Just request a mod to split your thread from this thread and make it an independent thread. I hardly go back in 'Resolved' threads. It was sheer luck that I saw your post

    <~~~~ You can use the exclamation icon in a triangle on the left hand side down below to request a mod
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

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



Click Here to Expand Forum to Full Width