我有一些代码可以将电子邮件导入表单。但是,它受压延机邀请的困扰。作为回应,我想过滤掉所有这些日历邀请,因此它们甚至都不打算首先导入。这是我到目前为止的代码:
from bs4 import BeautifulSoup
soup = BeautifulSoup(data, 'lxml')
print(soup.select_one("p > img").find_previous('p'))
问题出在 Dim SenderCheck As String
'Build the list selection box
j = 0
For i = 1 To Emails.Count
With ListBox_Emails
If TypeName(Item) = "MailItem" Then
SenderCheck = Emails(i).Sender.Address
If InStr(1, SenderCheck, "express-scripts.com") > 0 Then
.AddItem Emails(i).Sender
.List(j, 1) = Emails(i).Subject
.List(j, 2) = Emails(i).ReceivedTime
.List(j, 3) = "N"
j = j + 1
Else: MsgBox "error"
End If
Else: MsgBox "not mail item"
End If
End With
On Error GoTo TEMP
行,因为现在所有内容都被视为不是邮件,并且我收到“不是邮件”错误。
我将如何解决此问题?我认为语法不正确,但我不知道如何纠正它。
答案 0 :(得分:1)
这对我来说很好。它会跳过日历邀请
Option Explicit
Sub Sample()
Dim OutApp As Object
Dim oMail As Object, Item As Object
Dim objNS As Object, olFolder As Object
Set OutApp = CreateObject("Outlook.Application")
Set objNS = OutApp.GetNamespace("MAPI")
Set olFolder = objNS.GetDefaultFolder(6) '<~~ olFolderInbox = 6
For Each Item In olFolder.Items
'https://docs.microsoft.com/en-us/office/vba/api/outlook.olobjectclass
If Item.Class = 43 Then
Set oMail = Item
Debug.Print oMail.Subject
Debug.Print oMail.SenderEmailAddress
End If
Next
End Sub