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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Email Attachements

Status
Not open for further replies.

Trudye

Programmer
Sep 4, 2001
932
US
Hi Guys, I am trying to create a procedure that will open and save an email attachment. I’m getting a type mismatch on Set myolFolder = olnamespace.GetDefaultFolder("Inbox").


Public Function Get_Attachements()
Dim olapp As Outlook.Application
Dim olnamespace As 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 myolFolder = olnamespace.GetDefaultFolder("Inbox")


InDate = Format(Date, mmddyy)

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

For Each myItem In myolFolder.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

Also are my SUBJECT and FOLDER commans correct? Figured I may as well get as much out the way as I can (smile).

Thanks much,
Trudye
 
I’ve managed to clean it up a lot. 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

 
oops Sorry about that I forgot to insert the code:

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top