由于运行类型错误13 Outlook,代码未执行循环 [英] Code not executing the loop due to run type error 13 outlook

查看:102
本文介绍了由于运行类型错误13 Outlook,代码未执行循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试列出特定文件夹中电子邮件的所有主题.我收到的不是邮件项目(即约会等)的Run time Error 13

I'm trying to list out all the subjects of emails in a particular folder. I am getting a Run time Error 13 as soon as item not mail item, i.e.appointment, etc.

后续问题:

1)如何根据主题和电子邮件回复所有对最新电子邮件的邮件,这些邮件可以在收件箱"或已发送邮件"中.

1) How do reply to all to a latest email based the subject and email could be in Inbox or sent items.

2)如何循环进入文件夹中的所有电子邮件,即单击单击此处以在Microsoft Edge上查看更多信息",可以访问所有旧电子邮件.

2) How to loop in all emails in a folder, i.e. clicking "Click here to view more on Microsoft edge" give you access to all old emails.

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

推荐答案

以下内容...

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

这篇关于由于运行类型错误13 Outlook,代码未执行循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆