default mailbox and moving attachments

T

tigoda

I have found whilst look for help the nifty bit of code below,

It comes from a site called (if I remember correctly,) dicks-clicks.com

What it does it looks for files in my mailbox with a certain line in the
subject and moves that email elsewhere whilst at the same time pulling out
the attachment for the email and saving it where ever I want,

What I need to do is figure out how to make it look at another mailbox that
I use.

I was thinking it might be as simple as doing a

Dim mailbox as XZY

Then later on saying:

Mailbox = “reportsâ€

But for the life of me I don’t know what the XYZ bit is nor do I know of
another way to do this. The code for the main bit is:

Dim olApp As Outlook.Application
Dim olNs As Namespace
Dim Mailbox As mapi
Dim Fldr As MAPIFolder
Dim MoveToFldr As MAPIFolder
Dim olAtt As Attachment
Dim MyPath As String

Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")

Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
Set MoveToFldr = Fldr.Folders("reports")

For i = Fldr.Items.Count To 1 Step -1
Set olMi = Fldr.Items(i)
If InStr(1, olMi.Subject, "ERR00") > 0 Then
For Each olAtt In olMi.Attachments

olAtt.SaveAsFile MyPath & Mid(olAtt.Filename, 1, 21) &
".csv"

Next olAtt
olMi.Save
olMi.Move MoveToFldr
End If
Next i

Set olAtt = Nothing
Set olMi = Nothing
Set Fldr = Nothing
Set MoveToFldr = Nothing
Set olNs = Nothing
Set olApp = Nothing
Exit Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top