Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save Outlook attachment to file

Status
Not open for further replies.

Trudye

Programmer
Joined
Sep 4, 2001
Messages
932
Location
US
Hey Guys I am trying to save an Outlook attachment to a file via VBA. My problem is my FOR statement is incorrect. Obj. doesn't support this property or method.

I tried to pattern it after Help from the Microsoft. Of course we all know how abbreviated their help examples are.

Any help would be appreciated, thanx
Trudye

Public Function Get_Attachements()
Dim olApp As Outlook.Application
Dim olnamespace As Outlook.NameSpace
Dim myItem As MailItem
Dim olatt As Attachment
Dim myapp As Excel.Application
Dim InDate As Date
Set myapp = CreateObject("Excel.Application")


Set olApp = CreateObject("Outlook.Application")
Set olnamespace = olApp.GetNamespace("MAPI")
Set myItem = olApp.CreateItem(olMailItem)

Set myAtt = myItem.Attachments
Set olApp.ActiveExplorer.CurrentFolder = _
olnamespace.GetDefaultFolder(olFolderInbox)

InDate = Format(Date, mmddyy)

myItem.Subject = "Compiled_RPM_ " & InDate & ".xls"

For Each myItem In olApp.Items

If myItem.SenderName = "Varela, Angel" Then
For Each olatt In myItem.Attachments

myItem.SaveAsFile "C:\Mdb\DlrIntntPurchase-Notes\" & "RPMNotes.xls" & ".xls"
Next
End If

Next

End Function
 
You had it, I'm guessing this was at the end of a long day;)
Code:
...
For Each myItem In olApp.Items
    If myItem.SenderName = "Varela, Angel" Then
        For Each olatt In myItem.Attachments        
            '[s]myItem.SaveAsFile "C:\Mdb\DlrIntntPurchase-Notes\" & "RPMNotes.xls" & ".xls"[/s]
            [b]olatt[/b].SaveAsFile "C:\Mdb\DlrIntntPurchase-Notes\" & "RPMNotes.xls" & ".xls"
        Next
    End If

Next
...
CMP

Instant programmer, just add coffee.
 
Thank you so much for responding. I apolgize, I should have posted a follow-up here as I did on the VBA board.

Hi Everyone

Yesterday I asked for information on how to open a Outlook attachment and save it to file. Well I found the answer and thought it only fair I share it with everyone since all of you have been so kind to me over the years.

Here is the link:

Thank you all,
Be well
Trudye
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top