【发布时间】:2021-11-22 19:11:49
【问题描述】:
我正在将特定的电子邮件数据导出到 Excel。 如果用户在用户表单中输入错误的电子邮件标题然后我的 c
【问题讨论】:
我正在将特定的电子邮件数据导出到 Excel。 如果用户在用户表单中输入错误的电子邮件标题然后我的 c
【问题讨论】:
您无法通过Application.ActiveExplorer.CurrentFolder.Items(EmailTitle) 直接获取该项目。
您可以使用ActiveExplorer.CurrentFolder.Items(i) 一次查看所有项目。
用于演示。这是最慢的方式,但足以满足“合理”数量的项目。Find 或 Restrict 更可取。
Option Explicit
Private Sub CommandButtonS_click() 'Declare outlook variables
Dim currFolder As folder
Dim oLookObject As Object
Dim oLookMailitem As mailItem
Dim EmailTitle As String
Dim i As Long
Dim foundFlag As Boolean
EmailTitle = "Test"
Set currFolder = ActiveExplorer.CurrentFolder
' This is the slowest way but sufficient for a folder with a "reasonable" number of items.
' Find or restrict is preferable.
For i = 1 To currFolder.Items.Count
Set oLookObject = currFolder.Items(i)
If oLookObject.Class = olMail Then
Set oLookMailitem = oLookObject
' Now you may check for a mailitem property
If oLookMailitem.subject = EmailTitle Then
Debug.Print oLookMailitem.subject
'oLookMailitem.Display
foundFlag = True
Exit For ' Stop looking when item found.
End If
End If
Next
If foundFlag = False Then
MsgBox "This email is not in your current outlook email box Or incorrect email title." & _
vbCr & "Please choose the correct email box Or correct the email title."
End If
End Sub
【讨论】: