G
Guest
Hey
I wrote program to collect my attachments in one folder. I am using OE 2003.
The problem is , when I am using this program it doesn't took every mail it
leaves some of them. When I run it for second time it usually takes care
about the rest, but it should do it in one run. I am using following code:
For Each itm As Outlook.MailItem In fld.Items
For Each atch As Outlook.Attachment In itm.Attachments
Dim fi As New System.IO.FileInfo(atch.FileName)
Dim fname As String
Dim AttFile As System.IO.File
fname = pathNew & atch.FileName
If AttFile.Exists(fname) Then
' It gives just a random name for a file if the file with such a name
already exists
While AttFile.Exists(fname)
Dim rnd As New Random
fname = pathNew & rnd.Next(100, 999) &
fi.Extension
End While
End If
Try
atch.SaveAsFile(fname)
Catch ex As IO.IOException
MsgBox(ex.Message)
End Try
hasAttachment = True
Next
If hasAttachment Then
itm.Delete()
hasAttachment = False
End If
Next
I put the code above in a for loop to run it 5 times and it works perfectly,
why it doesn't clean everything in a first run ?
Jarod
I wrote program to collect my attachments in one folder. I am using OE 2003.
The problem is , when I am using this program it doesn't took every mail it
leaves some of them. When I run it for second time it usually takes care
about the rest, but it should do it in one run. I am using following code:
For Each itm As Outlook.MailItem In fld.Items
For Each atch As Outlook.Attachment In itm.Attachments
Dim fi As New System.IO.FileInfo(atch.FileName)
Dim fname As String
Dim AttFile As System.IO.File
fname = pathNew & atch.FileName
If AttFile.Exists(fname) Then
' It gives just a random name for a file if the file with such a name
already exists
While AttFile.Exists(fname)
Dim rnd As New Random
fname = pathNew & rnd.Next(100, 999) &
fi.Extension
End While
End If
Try
atch.SaveAsFile(fname)
Catch ex As IO.IOException
MsgBox(ex.Message)
End Try
hasAttachment = True
Next
If hasAttachment Then
itm.Delete()
hasAttachment = False
End If
Next
I put the code above in a for loop to run it 5 times and it works perfectly,
why it doesn't clean everything in a first run ?
Jarod