samuelimtech
01-29-2014, 03:19 AM
Hi all,
I have the following code to download all files from an outlook folder and save it in a specified folder. The script runs through one script then generates a run time error(****) when it tries to save from the next email. can anyone see why?
Dim myOlapp As Outlook.Application
Dim myNameSpace As Outlook.Namespace
Dim myFolder As Outlook.MAPIFolder
Dim myItem As Outlook.MailItem
Dim myAttachment As Outlook.Attachment
Dim i As Long
Set myOlapp = CreateObject("Outlook.Application")
Set myNameSpace = myOlapp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myFolder = myFolder.Folders("Timesheets") 'Change this!!!!!!!!!!!!!!!!!
For Each myItem In myFolder.Items
If myItem.Attachments.count <> 0 Then
For Each myAttachment In myItem.Attachments
i = i + 1
**** myAttachment.SaveAsFile "C:\Users\samuel.brierley\Desktop\Timesheets (STSS)\Download\" & myItem.Attachments.Item(i).Filename
Next
End If
Next
End Sub
I have the following code to download all files from an outlook folder and save it in a specified folder. The script runs through one script then generates a run time error(****) when it tries to save from the next email. can anyone see why?
Dim myOlapp As Outlook.Application
Dim myNameSpace As Outlook.Namespace
Dim myFolder As Outlook.MAPIFolder
Dim myItem As Outlook.MailItem
Dim myAttachment As Outlook.Attachment
Dim i As Long
Set myOlapp = CreateObject("Outlook.Application")
Set myNameSpace = myOlapp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myFolder = myFolder.Folders("Timesheets") 'Change this!!!!!!!!!!!!!!!!!
For Each myItem In myFolder.Items
If myItem.Attachments.count <> 0 Then
For Each myAttachment In myItem.Attachments
i = i + 1
**** myAttachment.SaveAsFile "C:\Users\samuel.brierley\Desktop\Timesheets (STSS)\Download\" & myItem.Attachments.Item(i).Filename
Next
End If
Next
End Sub