我撰寫了一個宏,只要郵件主題包含特定單詞,它就應該將收到的郵件的內容提取到 Excel 作業表中。總而言之,它的作業,但宏的第一部分在我收到郵件后立即執行(無論郵件有哪個主題)。每次我收到郵件時,都會在 Outlook 中彈出一個視窗,但我只希望它在收到包含特定主題內容的郵件時彈出。具體來說,我必須為以下行找到另一種解決方案:
If TypeName(item) = "MailItem" Then Set olMail = item
在整個代碼下方:
Private Sub olItems_ItemAdd(ByVal item As Object)
'Variablen dimensionieren
Dim olMail As Outlook.MailItem
Dim oxLApp As Object, oxLwb As Object, oxLws As Object
Set oxLApp = GetObject(, "Excel.Application")
Set oxLwb = oxLApp.Workbooks.Open _
("C:\Users\A2000\Desktop\Makros_NewScoping")
Set oxLws = oxLwb.Sheets("Slide 3")
'Prüfen ob Item eine Mail ist
If TypeName(item) = "MailItem" Then
Set olMail = item
If InStr(olMail.Subject, "APPROVAL REQUIRED") And _
olMail.SenderName = "Test, Name" Then
With oxLws
.Range("Q24") = olMail.VotingResponse
.Range("E41") = olMail.Body
End With
End If
uj5u.com熱心網友回復:
如果到達的郵件不符合您的條件,則無需運行任何額外的代碼:
Private Sub olItems_ItemAdd(ByVal item As Object)
'Variablen dimensionieren
Dim olMail As Outlook.MailItem
Dim oxLApp As Object, oxLwb As Object, oxLws As Object
'Prüfen ob Item eine Mail ist
If TypeName(item) = "MailItem" Then
Set olMail = item
If InStr(olMail.Subject, "APPROVAL REQUIRED") And _
olMail.SenderName = "Test, Name" Then
Set oxLApp = GetObject(, "Excel.Application")
Set oxLwb = oxLApp.Workbooks.Open _
("C:\Users\A2000\Desktop\Makros_NewScoping")
Set oxLws = oxLwb.Sheets("Slide 3")
With oxLws
.Range("Q24") = olMail.VotingResponse
.Range("E41") = olMail.Body
End With
End If
請注意,每次將新專案添加到檔案夾時創建一個新的 Excel 實體并不是一個好主意。此外,ItemAdd 事件不僅會針對傳入的電子郵件觸發,還會針對移至檔案夾的每封電子郵件觸發。因此,當將專案移動到檔案夾時,您將觸發代碼。
這就是為什么我建議處理班級NewMailEx事件的原因Application。對于 Microsoft Outlook 處理的每個收到的專案,此事件都會觸發一次。該專案可以是幾種不同的專案型別之一,例如MailItem、MeetingItem或SharingItem。該EntryIDsCollection字串包含對應于該專案的條目 ID。使用EntryIDCollection字串表示的條目 ID 呼叫NameSpace.GetItemFromID方法并處理專案。
uj5u.com熱心網友回復:
您需要將打開 Excel 的代碼移動到If檢查服務器和主題的陳述句下方。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/450644.html
