Solved

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

Posted on 2014-01-21
8
422 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 500 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

729 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