samuelimtech
08-26-2014, 02:15 AM
Hi all,
first of all thanks for any help.
I have the following code and for some reason it keeps failing at the next (just above the commented out error handler).
I cant see any issues in my logic and quite frankly its frustrating now. can anyone see where im going wrong. i have played around with error handlers in various positions but cant suss it out.
[Sub SaveAttachments()
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("TS")
For Each myItem In myFolder.Items
If myItem.Attachments.Count <> 0 Then
i = 1
For Each myAttachment In myItem.Attachments
'On Error GoTo Myerrorhandler
'MsgBox Right(myItem.Attachments.Item(i).FileName, 15)
If Right(myItem.Attachments.Item(i).FileName, 5) = ".xlsm" Then
myAttachment.SaveAsFile "T:\Inter Urban\Consultancy Services\Timesheets\Templates\Access\Download\" & myItem.Attachments.Item(i).FileName
Else
End If
i = i + 1
Next
End If
Next
'Myerrorhandler:
Exit Sub
Resume Next
End Sub
first of all thanks for any help.
I have the following code and for some reason it keeps failing at the next (just above the commented out error handler).
I cant see any issues in my logic and quite frankly its frustrating now. can anyone see where im going wrong. i have played around with error handlers in various positions but cant suss it out.
[Sub SaveAttachments()
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("TS")
For Each myItem In myFolder.Items
If myItem.Attachments.Count <> 0 Then
i = 1
For Each myAttachment In myItem.Attachments
'On Error GoTo Myerrorhandler
'MsgBox Right(myItem.Attachments.Item(i).FileName, 15)
If Right(myItem.Attachments.Item(i).FileName, 5) = ".xlsm" Then
myAttachment.SaveAsFile "T:\Inter Urban\Consultancy Services\Timesheets\Templates\Access\Download\" & myItem.Attachments.Item(i).FileName
Else
End If
i = i + 1
Next
End If
Next
'Myerrorhandler:
Exit Sub
Resume Next
End Sub