S
Steph
Hello. I have some code below that takes all the emails within an inbox and
saves each .xls attachment to a predefined path on the server. This code
has worked great during internal testing (ie when peoplw within our domain
send emails to the inbox). BUT, when someone from outside the company sends
an e-mail to it, the email comes in as a "discussion" posting to the inbox.
The code below doesn't seem to recognize that and it errors out (Type
mismatch on the line For i = fldr.Items.Count To 1 Step -1). Any ideas?
Thanks!
Sub SaveAtt()
'Saves attachments to a folder
Dim ol As Outlook.Application
Dim ns As Namespace
Dim fldr As MAPIFolder
Dim Mi As MailItem
Dim Att As Attachment
Dim i As Long
Dim iFile As Long
Dim MyPath As String
Set ol = New Outlook.Application
Set ns = ol.GetNamespace("MAPI")
Set fldr = ns.Folders("Public Folders").Folders("All Public
Folders").Folders("My Folder")
MyPath = "\server\myserver\myfolder\"
For i = fldr.Items.Count To 1 Step -1
Set Mi = fldr.Items(i)
If Mi.Attachments.Count > 0 Then
For Each Att In Mi.Attachments
iFile = iFile + 1
Att.SaveAsFile MyPath & Format(Mi.ReceivedTime,
"yyyymmddhhmmss") & "-" & CStr(iFile) & ".xls"
Next Att
Mi.Save
End If
Next i
Set Att = Nothing
Set Mi = Nothing
Set fldr = Nothing
Set ns = Nothing
Set ol = Nothing
Set MoveToFldr = Nothing
End Sub
saves each .xls attachment to a predefined path on the server. This code
has worked great during internal testing (ie when peoplw within our domain
send emails to the inbox). BUT, when someone from outside the company sends
an e-mail to it, the email comes in as a "discussion" posting to the inbox.
The code below doesn't seem to recognize that and it errors out (Type
mismatch on the line For i = fldr.Items.Count To 1 Step -1). Any ideas?
Thanks!
Sub SaveAtt()
'Saves attachments to a folder
Dim ol As Outlook.Application
Dim ns As Namespace
Dim fldr As MAPIFolder
Dim Mi As MailItem
Dim Att As Attachment
Dim i As Long
Dim iFile As Long
Dim MyPath As String
Set ol = New Outlook.Application
Set ns = ol.GetNamespace("MAPI")
Set fldr = ns.Folders("Public Folders").Folders("All Public
Folders").Folders("My Folder")
MyPath = "\server\myserver\myfolder\"
For i = fldr.Items.Count To 1 Step -1
Set Mi = fldr.Items(i)
If Mi.Attachments.Count > 0 Then
For Each Att In Mi.Attachments
iFile = iFile + 1
Att.SaveAsFile MyPath & Format(Mi.ReceivedTime,
"yyyymmddhhmmss") & "-" & CStr(iFile) & ".xls"
Next Att
Mi.Save
End If
Next i
Set Att = Nothing
Set Mi = Nothing
Set fldr = Nothing
Set ns = Nothing
Set ol = Nothing
Set MoveToFldr = Nothing
End Sub