Object Not supported
I was going through the following code but it doesn't seem to work on my computer. It gives an error: Object Not Supported at the Format(Item.ReceivedTime, "MMDDYYYY") = Format(Now, "MMDDYYYY") part.
I created a folder named ELN in my inbox and placed an email there with a .xls file, but its still not working. I have added the DOA and Outlook References in Excel.Any advice?
Dim appOl As New Outlook.Application
Dim ns As Outlook.Namespace
Dim Inbox As Outlook.MAPIFolder
Dim Atmt As Outlook.Attachment
Dim开发者_开发技巧 SubFolder As Outlook.MAPIFolder
Dim Item As Object
Dim FileName As String
Dim i As Integer
Dim varResponse As VbMsgBoxResult
Set ns = appOl.GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set SubFolder = Inbox.Folders("ELN")
i = 0
For Each Item In SubFolder.Items
If Format(Item.ReceivedTime, "MMDDYYYY") = Format(Now, "MMDDYYYY") Then
For Each Atmt In Item.Attachments
If Right(Atmt.FileName, 3) = "xls" Then
FileName = "SomeFile.xls"
Atmt.SaveAsFile FileName
smkSubject = Item.Subject
i = i + 1
End If
Next Atmt
End If
Next Item
The "item" may or may not be a mail item.
This might do the trick:
For Each Item In Inbox.Items
If Item.Class = olMail Then 'Make sure it's a mail item
If Format(Item.ReceivedTime, "MMDDYYYY") = Format(Now, "MMDDYYYY") Then
For Each Atmt In Item.Attachments
If Right(Atmt.FileName, 3) = "doc" Then
FileName = "SomeFile.xls"
Atmt.SaveAsFile FileName
smkSubject = Item.Subject
i = i + 1
End If
Next Atmt
End If
Else
Debug.Print "This is not a mail item:" & Item.Class 'Some class constant that's not supported as a mail item.
End If
Next Item
精彩评论