2017-06-29 47 views
-1

我需要在Outlook 2016中創建一個規則,當「CC:」字段中有超過10個電子郵件地址時,該規則將彈出警告。如何根據「CC:」地址的數量制定Outlook規則?

我在一個快速的谷歌搜索找到了這個結果,它做了同樣的事情,但與「收件人:」字段中的電子郵件地址。我是VBA的新手,因此我不確定需要更改哪條線來切換它以查看CC電子郵件而不是To。

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) 
    Dim Recipients As Integer 
    Dim Start As Integer 
    Dim Last As Integer 
    Recipients = 1 
    Do 
     Start = Last + 1 
     Last = InStr(Start, Item.To, ";") 
     If Last = 0 Then Exit Do 
     Recipients = Recipients + 1 
    Loop 
    If (Recipients > 10) Then 
     Cancel = (MsgBox(Str(Recipients) & " recipients in To field.", vbOKCancel) = vbCancel) 
    End If 
End Sub 
+0

'item.cc' https://msdn.microsoft.com/VBA/Outlook-VBA/articles/mailitem-cc-property-outlook –

+1

另外,'Recipients = ubound(split(item.cc,「;」))'應該做count,所以不需要代碼到IF –

回答

0

我無法發佈「評論」,所以我張貼的「回答」

「分割」函數返回一個數組,這是基於零(第一元件是在索引0)

因此

,UBOUND對於10元件陣列

這裏是代碼返回一個如圖9所示,與由Nathan_Sav建議的變化,

加在代碼的變化來添加一個至t他導致UBound函數

也...對話框,當有太多的收件人彈出的,並沒有提及會發生什麼,當你按下任一按鈕

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) 

    Dim Recipients As Integer 

    Recipients = ubound(split(item.cc,";")) + 1 ' shift array index by one 

    If (Recipients > 10) Then 
     Cancel = (MsgBox(Str(Recipients) & " recipients in CC field.", vbOKCancel) = vbCancel) 
    End If 

End Sub 
相關問題