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

Accessing an outlook emial folder

Status
Not open for further replies.

amal1973

Technical User
Jul 31, 2001
131
0
0
US
I have sent 150 emails with excel workbooks as attachments. How can I by code access my Outlook Email Box (IECG) and loop through all received email and access the excel workbooks.the reson is to populate an Access database with the workboos data, and i had this part work. And If possible the emails that have been gone through the first time the code runs should not go through them the second time.

Appreciate any help.
 
i want to find the code for looping through the attachment
in the email box.
 
Hi, here's bit of a solution - this will go thru your default inbox in outlook and save all the attachment files in it that end in xls into G:\testvery rough and ready and outlook will probably shout at you saying do you want to allow this. no trapping. don't know what happens if you have duplicate filenames.
i've left all my testing msgboxes in, but remmed out.
alasdair

Code:
Sub OutTest()

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace("MAPI")
Rem MsgBox myNameSpace.CurrentUser
 Set myfolder = _
    myNameSpace.GetDefaultFolder(6) ' folder 6 is default inbox
Rem MsgBox myfolder.Name & " contains " & myfolder.items.Count & " items"

counter = 1
For counter = 1 To myfolder.items.Count
Rem MsgBox myfolder.items.Item(counter).attachments.Count
If myfolder.items.Item(counter).attachments.Count > 0 Then
Set myattachs = myfolder.items.Item(counter).attachments
attcounter = 1
For attcounter = 1 To myattachs.Count
Rem MsgBox myattachs(attcounter) & vbCr & "number " & attcounter & " of " & myattachs.Count
If Right(myattachs(attcounter), 3) = "xls" Then
myattachs(attcounter).SaveAsFile ("G:\test\") & myattachs(attcounter)
End If

Next
End If

Next


End Sub
 
Thanks for your solution; it provided most of my solution, thanks. I want to play with it and try to get the subject and to make sure that if a file was picked one time it won’t be picked the second time it loops inside the inbox.."-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top