Outlook VBA ReceivedTime“无效限定符”

时间:2014-11-21 17:08:46

标签: outlook-vba

我正在尝试编写一个采用特定消息的Outlook宏(如下面宏中所示的“Selection”消息),并根据其ReceivedTime属性将消息的附件保存在文件夹中。目的是最终扩展宏以在Excel中打开附件并在其上运行已经编写的Excel宏,但我试图从小开始。

但是,每当我尝试运行下面的宏时,它都说ReceivedTime属性是“无效的限定符”。我以前从未见过这个错误,也不知道它意味着什么或做什么。

Sub DailyPinkOL()
    Call initMonths
    Dim inbox As Folder
    Dim att As Attachment
    Dim FilePath As String
    Dim SaveFolder As String
    Dim mi As MailItem
    Dim xlapp As Excel.Application
    Dim xlwb As Excel.Workbook
    Dim xlat As Excel.Workbook
    Set inbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
    If Selection.Location <> olViewList Then Exit Sub
    Set mi = Selection
    Set att = mi.Attachments(1)
    att.SaveAsFile Path:="path1\Current Year\" & months(mi.ReceivedTime.Month) & "\" & mi.ReceivedTime.Month & "-" & mi.ReceivedTime.Day & ".xlsx"
    Set xlapp = CreateObject("Excel.Application")
    Set xlwb = xlapp.Workbooks.Open("path2\file1")
End Sub

path1,path2和file1被实际宏中的实际文件路径和文件替换;为了安全起见,我这样复制了它。

1 个答案:

答案 0 :(得分:0)

att.SaveAsFile Path:="path1\Current Year\" & months(mi.ReceivedTime.Month) & "\" & mi.ReceivedTime.Month & "-" & mi.ReceivedTime.Day & ".xlsx"
就我看来,

有两个错误:

mi.ReceivedTime.Month不存在;转而去月(mi.ReceivedTime)。

mi.ReceivedTime.Day不存在;转到日(mi.ReceivedTime)而不是

所以它应该是:

att.SaveAsFile Path:="path1\Current Year\" & month(mi.ReceivedTime) & "\" & month(mi.ReceivedTime) & "-" & day(mi.ReceivedTime) & ".xlsx"

你还有其他代码我不会解决(和我的Outlook抛出错误)之类的     如果Selection.Location&lt;&gt; olViewList然后退出Sub     调用initMonths 但如果他们为你工作一切都很好......

最高