Vba 设置outlook.attachment=邮件项目附件
我正在尝试编写一个脚本,将附件保存到目录中。当我运行它时,我会收到一条错误消息“type mismatch”,并突出显示行Vba 设置outlook.attachment=邮件项目附件,vba,attachment,mailitem,Vba,Attachment,Mailitem,我正在尝试编写一个脚本,将附件保存到目录中。当我运行它时,我会收到一条错误消息“type mismatch”,并突出显示行Set olAtt=olMi.Attachments。有人能提供建议吗 Sub SaveAttachments() Dim olApp As Outlook.Application Dim olNs As Namespace Dim Fldr As MAPIFolder Dim MoveToFldr As MAPIFolder Dim olMi As Outlook.Mai
Set olAtt=olMi.Attachments
。有人能提供建议吗
Sub SaveAttachments()
Dim olApp As Outlook.Application
Dim olNs As Namespace
Dim Fldr As MAPIFolder
Dim MoveToFldr As MAPIFolder
Dim olMi As Outlook.MailItem
Dim olAtt As Outlook.Attachment
Dim MyPath As String
Dim i As Long
Dim j As Long
Dim filesavename As String
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
Set MoveToFldr = Fldr.Folders("Survey")
MyPath = "C:\Users\temp"
For i = (Fldr.Items.Count - 150) To Fldr.Items.Count
Set olMi = Fldr.Items(i)
If InStr(1, olMi.Subject, "Survey") > 0 Then
j = olMi.Attachments.Count
Set olAtt = olMi.Attachments
filesavename = MyPath & olAtt.Filename
olAtt.SaveAsFile filesavename
olMi.Save
olMi.Move MoveToFldr
End If
Next i
Set olAtt = Nothing
Set olMi = Nothing
Set Fldr = Nothing
Set MoveToFldr = Nothing
Set olNs = Nothing
Set olApp = Nothing
End Sub
olAtt
声明为Outlook.Attachment
(单数)
olMi.Attachments
是附件的集合