2017-08-07 15 views
0

我有一個處理任何傳入項目的Outlook代碼,並且如果傳遞給定條件,則僅在郵件項目中創建Outlook日曆中的新約會。代碼忽略傳入的會議請求

該代碼不區分郵件項目和會議請求項目。這會導致系統在1899年從會議項目中創建一個新會議,而忽略這一點。

Private Sub Application_NewMailEx(ByVal EntryIDCollection As String) 

On Error Resume Next 
Set ns = Application.Session 
arr = Split(EntryIDCollection, ",") 


For i = 0 To UBound(arr) 
    Set itm = ns.GetItemFromID(arr(i)) 

    If (itm.Class = olMail) Then 

     Set objMail = itm 

     If objMail.Subject = "Approved" And objMail.Sender = "[email protected]" Then 

      Set Reg1 = New RegExp 

      With Reg1 
        .Pattern = "([0-9]{2})(.)([0-9]{2})(.)([0-9]{4})(\s)(\W)(\s)([0-9]{2})(.)([0-9]{2})(.)([0-9]{4})" 
        .Global = True 
      End With 

      If Reg1.test(objMail.Body) Then 

       Set M1 = Reg1.Execute(objMail.Body) 

       For Each m In M1 

       Set objAppt = Application.CreateItem(olAppointmentItem) 
       Set objInsp = objAppt.GetInspector 
       Set objDoc = objInsp.WordEditor 
       Set objSel = objDoc.Windows(1).Selection 

       Next 
      End if 
      ..... 

End Sub 
+1

[文檔](https://msdn.microsoft.com/VBA/Outlook-VBA/articles/create-an-appointment-as-a-會議在日曆上)建議您應設置[MeetingRequest屬性](https://msdn.microsoft.com/VBA/Outlook-VBA/articles/appointmentitem-meetingstatus-property-outlook) - 'objAppt.MeetingStatus = olMeeting' – stuartd

+0

那麼確切的問題是什麼?檢查「If(itm.Class = olMail)Then」告訴你它是一個郵件項目,而它是一個會議項目? –

+0

在郵箱中發送並接收到會議請求後,預期的結果是,由於只處理郵件,因此它將失敗,因爲只有郵件需要處理。沒有會議被創建。現在的實際結果是創建了空主題行,空位置行和開始時間30.12.1899和結束時間29.12.1899的全天事件。此外,事件正文還包含處理郵件的部分代碼 –

回答

0

基礎上OP的評論「運行時錯誤‘13’,對於ITM變量類型不匹配」,並解決發展問題,這個問題的答案很可能固定在錯誤恢復的濫用接下來,設置編輯器在每個模塊上生成Option Explicit。

編程變化應然後是:

Dim itm As Object 
Dim objMail As MailItem 
0

你需要檢查傳入項目的Class財產以下列方式:

If (itm.Class = olMail) Then 

    Set objMail = itm 
    ... 
    End If 

    If (itm.Class = olMeetingRequest) Then 

    Set objMeeting = itm 
    ... 
    End If 
+0

我創建了基本日誌並對其進行了測試。它適用於傳入郵件,寫入類43.但是,這個問題是代碼無法識別olMeetingRequest的類。它完全忽略它。它不會在日誌中寫入任何內容。 'If it.Class = olMeetingRequest Then ws.Range(「E」&lr)= itm.Class End If' –

0

解決與另一thread幫助。

Dim itm As Object 
Dim oMail As MailItem 

If TypeName(itm) = "MailItem" Then 

    Set oMail = itm 
    .... 
End if