当前位置: 首页 > 知识库问答 >
问题:

对象不支持此属性或方法接收时间

谭成业
2023-03-14

我是VB代码的新手,我正在尝试执行下面的代码。但是我收到一条错误消息,此行对象不支持此属性或方法

If VBA.DateValue(VBA.Now) - VBA.DateValue(Folder.Items.Item(iRow).ReceivedTime) <= 60 Then

我认为我的代码没有读取< code>ReceivedTime。我正在使用微软Excel 2010。我如何修理它?

Option Explicit

Sub Download_Outlook_Mail_To_Excel()
    'Add Tools->References->"Microsoft Outlook nn.n Object Library"
    'nn.n varies as per our Outlook Installation
    Dim Folder As Outlook.MAPIFolder
    Dim sFolders As Outlook.MAPIFolder
    Dim iRow As Integer, oRow As Integer
    Dim MailBoxName As String, Pst_Folder_Name  As String

    'Mailbox or PST Main Folder Name (As how it is displayed in your Outlook Session)
    MailBoxName = "xxxx@yyyy.com"

    'Mailbox Folder or PST Folder Name (As how it is displayed in your Outlook Session)
    Pst_Folder_Name = "Inbox" 'Sample "Inbox" or "Sent Items"

    'To directly a Folder at a high level
    Set Folder = Outlook.Session.Folders(MailBoxName).Folders(Pst_Folder_Name)

    'To access a main folder or a subfolder (level-1)
    For Each Folder In Outlook.Session.Folders(MailBoxName).Folders
        If VBA.UCase(Folder.Name) = VBA.UCase(Pst_Folder_Name) Then GoTo Label_Folder_Found
        For Each sFolders In Folder.Folders
            If VBA.UCase(sFolders.Name) = VBA.UCase(Pst_Folder_Name) Then
                Set Folder = sFolders
                GoTo Label_Folder_Found
            End If
        Next sFolders
    Next Folder

Label_Folder_Found:
     If Folder.Name = "" Then
        MsgBox "Invalid Data in Input"
        GoTo End_Lbl1:
    End If

    'Read Through each Mail and export the details to Excel for Email Archival
    ThisWorkbook.Sheets(1).Activate
    Folder.Items.Sort "Received"

    'Insert Column Headers
    ThisWorkbook.Sheets(1).Cells(1, 1) = "Body"

    'Export eMail Data from PST Folder
    oRow = 1
    For iRow = 1 To Folder.Items.Count
        'If condition to import mails received in last 60 days
        'To import all emails, comment or remove this IF condition
        If VBA.DateValue(VBA.Now) - VBA.DateValue(Folder.Items.Item(iRow).ReceivedTime) <= 60 Then

         '  ThisWorkbook.Sheets(1).Cells(oRow, 1).Select
           oRow = oRow + 1
           ThisWorkbook.Sheets(1).Cells(oRow, 1) = Folder.Items.Item(iRow).Body
        End If
    Next iRow
    MsgBox "Outlook Mails Extracted to Excel"
    Set Folder = Nothing
    Set sFolders = Nothing

End_Lbl1:
End Sub

共有1个答案

史逸春
2023-03-14

很可能您遇到的是MailItem以外的项,最可能是ReportItem,它不公开ReceivedTime属性。

添加额外的检查,将类属性(由所有Outlook对象公开)设置为43(olMail)。

另一方面,您正在使用多点表示法,这是一个非常糟糕的主意:

   dim vItems as Outlook.Items 
   dim vItem As Object

   set vItems =  Folder.Items
   For iRow = 1 To vItems.Count
           set vItem = vItems.Item(iRow) 
           if vItem.Class = 43 Then
                'If condition to import mails received in last 60 days
                'To import all emails, comment or remove this IF condition
                If VBA.DateValue(VBA.Now) - VBA.DateValue(vItem.ReceivedTime) <= 60 Then
                   oRow = oRow + 1
                   ThisWorkbook.Sheets(1).Cells(oRow, 1) = vItem.Body
                End If
            End If
     Next iRow
 类似资料:
  • 我需要简单地计算一张纸上的区域数。我的密码是: 但是由于某种原因,我收到错误消息“Object 不支持此属性或方法。”我不知道为什么。这段代码基本上只是从微软网站复制的。 我甚至无法使用即时窗口打印部分。 有什么快速的帮助吗?我正在使用Excel 2010。 谢了。

  • 我有以下rails配置: 有没有人对是什么导致了这个错误有什么建议?

  • 问题内容: 我在Surface Pro 3上安装了Rails,并在尝试查看页面后遇到此错误。我尝试了一些建议,例如使用libv8安装rubyracer,但没有帮助。 TypeError:对象不支持此属性或方法(在c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/turbolinks-2.5.3/lib/assets/javascripts/t

  • TypeError:对象不支持此属性或方法(在C:/RailsInstaller/Ruby2.0.0/Lib/Ruby/Gems/2.0.0/Gems/Turbolinks-2.5.3/Lib/Assets/JavaScripts/Turbolinks.js.coffee中) 这是我的Gemfile:

  • 本文向大家介绍对象不支持此属性或方法: Session.CodePage = 936 解决方法,包括了对象不支持此属性或方法: Session.CodePage = 936 解决方法的使用技巧和注意事项,需要的朋友参考一下 今天调试网站时在后台出现这样的错误,“Microsoft VBScript 运行时错误 '800a01b6' 对象不支持此属性或方法: 'Session.CodePage'”

  • 问题内容: 我的应用程序中有一个选项,用户可以停用其个人资料。只有管​​理员可以再次激活它们。 我有一类有两种方法 检查具有该userName的用户是否存在并且其个人资料已停用 然后再次激活用户的个人资料 我在输入类型按钮的click事件上调用JavaScript函数。这段代码在Chrome和Mozilla上正常运行,但是在Internet Explorer上却出现此错误: SCRIPT438:对