代码不执行,由于运行错误类型13展望循环

问题描述 投票:-1回答:1

我想列出电子邮件的所有受试者在一个特定的文件夹中。我立即得到一个Run time Error 13作为项目不邮件项目,i.e.appointment等。

后续问题:

1)如何回复所有基于主题和电子邮件中的最新电子邮件可以在收件箱或已发信息。

2)如何循环中的所有邮件文件夹中,即点击“点击这里查看更多关于微软边缘”给你访问所有的旧电子邮件。

Sub AccessInbox2()

'Early binding

Dim Olook As Outlook.Application ' to access all the libraries of outlook
Dim OmailItem As Outlook.MailItem ' To access emails in the inbox
Dim ONameSpace As Outlook.Namespace ' it is class which opens the gate for you to access all outlook folders. Unlike the Folder class, it exactly tells VBA which folder to use.
Dim Fol As Outlook.Folder ' Where we have emails with attachments stored
Dim Atmt As Outlook.Attachment ' a class which will help us in dealing wiht emails which as attachements
Dim TotalEmails As Long
Dim i As Integer


Set Olook = New Outlook.Application
Set OmailItem = Olook.CreateItem(olMailItem) 'to deal with emails

'messaging application protocal interface
i = 1
For Each OmailItem In Olook.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("Goldy").Items

    'If TypeName(OmailItem) = "MailItem" Then
    If OmailItem.Class = 43 Then

    Sheet1.Cells(i, 7).Value = OmailItem.Subject

    End If

i = i + 1
Next

End Sub
excel vba email outlook
1个回答
0
投票

如何以下...

Option Explicit
Public Sub AccessInbox2()
'Early binding
    Dim Olook As Outlook.Application ' to access all the libraries of outlook
    ' it is class which opens the gate for you to access
    ' all outlook folders. Unlike the Folder class,
    ' it exactly tells VBA which folder to use.

    Set Olook = New Outlook.Application

    Dim Sht As Worksheet
    Set Sht = ThisWorkbook.Sheets("Sheet1")



    Dim Items As Outlook.Items
    Set Items = Olook.GetNamespace("MAPI") _
                     .GetDefaultFolder(olFolderInbox) _
                     .Folders("Goldy").Items

   Dim i As Long
   Dim LastRow As Long
   For i = Items.Count To 1 Step -1

        If TypeOf Items(i) Is Outlook.MailItem Then
            Debug.Print Items(i).Subject ' Print on Immediate Window

            With Sht

                 LastRow = .Cells(.Rows.Count, 7).End(xlUp).Row + 1
                 Debug.Print .Cells(LastRow, 7).Address ' Print on Immediate Window
                .Cells(LastRow, 7).Value = Items(i).Subject

            End With

        End If

    Next

End Sub
© www.soinside.com 2019 - 2024. All rights reserved.