我正在尝试将传入电子邮件的主题与Excel主列表进行匹配,以查看该电子邮件之前是否已存在/已提取 . 如果匹配或存在,则它将显示某些内容或从电子邮件中提取消息 .
下面的代码没有显示任何结果 .
Public Sub MatchAutoAckv1()
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim obj As Object
Dim objOL As Outlook.Application
Dim objItems As Outlook.Items
Dim myItem As MailItem
Dim StrBody As String
Dim TotalRows As Long, i As Long
Dim myXLApp As Excel.Application
Dim myXLWB As Excel.Workbook
Dim exSubj As String
Set objOL = Outlook.Application
Set objNS = Application.Session
Set objFolder = Session.GetDefaultFolder(olFolderInbox).Folders("For Processing")
Set objItems = objFolder.Items
Set myXLApp = New Excel.Application
myXLApp.Visible = True
Set myXLWB = myXLApp.Workbooks.Open("C:\Users\username\Desktop\SR Automation Project\SR Historyv2.xlsx")
Set excWks = myXLWB.Worksheets("Sheet1")
lgLastRow = excWks.Range("C65536").End(xlUp).Row
i = lgLastRow + 1
Dim lgCurrentRow As Long
For Each obj In objItems
For lgCurrentRow = 2 To lgLastRow
Cells(lgCurrentRow, "C") = exSubj
If obj.Subject = exSubj Then
Debug.Print obj.Subject
End If
Next
Next
Set obj = Nothing
Set objItems = Nothing
Set objFolder = Nothing
Set objOL = Nothing
End Sub
1 回答
我建议你总是使用Option Explicit . 如果您不知道如何声明变量,请将其保留为没有类型 .
试试这个: