我有一段腳本,隨着時間的推移拼湊起來。最近我們需要在Outlook中使用一個插件導致了一些問題。基本上我們會得到兩次提示,因爲當使用插件時,電子郵件最終會被銷燬並用特定的附件文件名重新創建。此時會再次提示用戶。我試圖在For循環中工作,如果它找到了這個附件,就跳過腳本。但是,當我添加For循環時,它似乎忽略了整個腳本。我對VBA的經驗有限,所以我確信這是我的語法或用法的問題。請參見下面的腳本:VBA展望腳本
Private Sub Application_ItemSend _
(ByVal Item As Object, Cancel As Boolean)
Dim strMsg As String
Dim Atmt As Variant
'strMsg = Item.Class
If Item.Class = "43" Then
For Each Atmt In Item.Attachments
If VBA.Right(Atmt.FileName, 3) = ".sf" Then
GoTo NonEmailError
End If
Next Atmt
If Item.CC = "" Then
strMsg = "To recipients: " & Item.To & vbCrLf & _
"Are you sure you want to send this message?"
Else
strMsg = "To recipients: " & Item.To & vbCrLf & _
"Cc recipients: " & Item.CC & vbCrLf & _
"Bcc recipients: " & Item.BCC & vbCrLf & _
"Are you sure you want to send this message?"
End If
Else
GoTo NonEmailError
End If
' Exit Sub
' Ignore errors for now.
On Error GoTo NonEmailError
' Prompt user to fill in subject
If Item.Subject = "" Then
MsgBox "You must enter a subject.", 48, "Empty Subject"
Cancel = True
GoTo NonEmailError
End If
' Exit Sub
' Prompt user to verify E-Mails
If MsgBox(strMsg, vbYesNo + vbQuestion _
, "Send Confirmation") = vbNo Then
Cancel = True
End If
Exit Sub
NonEmailError:
' The item being sent was not an e-mail and so don't prompt the user anything
Exit Sub
End Sub
有幾點意見:1)不管電子郵件是否有附件,這兩個提示都會顯示出來嗎? 2)哪一行是與第一個提示相關聯的,哪一行是第二個? 3)它可能是一個好主意,而不是一個'對象'的工作,'暗淡olMI作爲Outlook.MailItem ---如果TypeName(Item)=「MailItem」然後---設置olMI =項目---'做你的東西---如果「。 –