?
Solved

How to save an Outlook 2010 email with an excel attachment to a folder?

Posted on 2014-01-21
8
Medium Priority
?
424 Views
Last Modified: 2014-02-04
When I get an email in Outlook 2010 with the subject contains the word "TEC" I need to save to a folder.
The VBA code to save an excel file to a folder will be set off by a outlook rule.
The path for the folder is...\\psf\Home\TEC Reports
Thanks,
Jimi
0
Comment
Question by:Jimi Sherman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 39

Accepted Solution

by:
nutsch earned 2000 total points
ID: 39799150
Something like this?

Sub SaveAttachment()
Dim sPath As String, sPathC As String
Dim lPos As Long
Dim MyFile As String
Dim sAmount As String, dAmount As Double
Dim colAttachments As Outlook.Attachments
Dim objAttachment As Outlook.attachment
Dim FolderPath As String

    Dim curmail As Outlook.MailItem, sCat As String
    Set curmail = GetCurrentItem()
      
    Set colAttachments = curmail .Attachments
    
    FolderPath = "\\psf\Home\TEC Reports"
    
For Each objAttachment In colAttachments
    
        MyFile = objAttachment.FileName
        sPath = FolderPath & "\" & MyFile
        objAttachment.SaveAsFile sPath

    Next
   
   curMail.Delete
   
    'Cleanup
    Set objAttachment = Nothing
    Set colAttachments = Nothing
    Set MyOlApplication = Nothing
    Set myOlSelection = Nothing
    Set mySelectedItem = Nothing

End Sub

' From http://www.outlookcode.com/codedetail.aspx?id=50
Function GetCurrentItem() As Object
    Dim objApp As Outlook.Application
         
    Set objApp = CreateObject("Outlook.Application")
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
        Case "Explorer"
            Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
        Case Else
            ' anything else will result in an error, which is
            ' why we have the error handler above
    End Select
     
    Set objApp = Nothing
End Function

Open in new window


Thomas
0
 

Author Comment

by:Jimi Sherman
ID: 39799186
The code stops at...
objAttachment.SaveAsFile sPath

Jimi
0
 
LVL 39

Expert Comment

by:nutsch
ID: 39799910
Does the following path exist?  
\\psf\Home\TEC Reports
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

Author Comment

by:Jimi Sherman
ID: 39800424
Yes
0
 
LVL 39

Expert Comment

by:nutsch
ID: 39800474
Any error message you're getting?
0
 

Author Comment

by:Jimi Sherman
ID: 39800531
No error message it just stops with the debug box opens.
I got it to work when I changed the path to...."C:\Users\Jimi\Documents"
So if you want i can close the question and issues you the points of courses?

Jimi
0
 
LVL 39

Expert Comment

by:nutsch
ID: 39800694
Can you map a drive to your destination? Does it work then?
0
 

Author Comment

by:Jimi Sherman
ID: 39800730
Yes it works then.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question