用于 Outlook 附件安全发送的 VB 代码
我对VB一无所知。我有以下代码,如果邮件正文中提到“附件”一词,则会弹出提醒。我想要的是提醒邮件是否包含附件,并询问邮件是否应该安全发送(加密)。
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
‘ Pops up a reminder if the word “attach” is found but there is no attachment on your email.
Dim m As Variant
Dim strBody As String
Dim intIn As Long
Dim intAttachCount As Integer, intStandardAttachCount As Integer
On Error GoTo handleError
‘Edit the following line if you have a signature on your email that includes images or other files. Make intStandardAttachCount equal the number of files in your signature.
intStandardAttachCount = 0
strBody = LCase(Item.Body)
intIn = InStr(1, strBody, “original message”)
If intIn = 0 Then intIn = Len(strBody)
intIn = InStr(1, Left(strBody, intIn), “attachment”)
intAttachCount = Item.Attachments.Count
If intIn > 0 And intAttachCount <= intStandardAttachCount Then
m = MsgBox(“It appears that you mean to send an attachment,” & vbCrLf & “but there is no attachment to this message.” & vbCrLf & vbCrLf & “Do you still want to send?”, vbQuestion + vbYesNo + vbMsgBoxSetForeground)
If m = vbNo Then Cancel = True
End If
handleError:
If Err.Number <> 0 Then
MsgBox “Outlook Attachment Reminder Error: ” & Err.Description, vbExclamation, “Outlook Attachment Reminder Error”
End If
End Sub
I know nothing about VB. I have the following code to have a reminder pop up if the word "attachment" is mentioned in the message body. What I want is a reminder if the message includes an attachment and ask if the message should be sent securely (encrypted).
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
‘ Pops up a reminder if the word “attach” is found but there is no attachment on your email.
Dim m As Variant
Dim strBody As String
Dim intIn As Long
Dim intAttachCount As Integer, intStandardAttachCount As Integer
On Error GoTo handleError
‘Edit the following line if you have a signature on your email that includes images or other files. Make intStandardAttachCount equal the number of files in your signature.
intStandardAttachCount = 0
strBody = LCase(Item.Body)
intIn = InStr(1, strBody, “original message”)
If intIn = 0 Then intIn = Len(strBody)
intIn = InStr(1, Left(strBody, intIn), “attachment”)
intAttachCount = Item.Attachments.Count
If intIn > 0 And intAttachCount <= intStandardAttachCount Then
m = MsgBox(“It appears that you mean to send an attachment,” & vbCrLf & “but there is no attachment to this message.” & vbCrLf & vbCrLf & “Do you still want to send?”, vbQuestion + vbYesNo + vbMsgBoxSetForeground)
If m = vbNo Then Cancel = True
End If
handleError:
If Err.Number <> 0 Then
MsgBox “Outlook Attachment Reminder Error: ” & Err.Description, vbExclamation, “Outlook Attachment Reminder Error”
End If
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Mihn,我想将此作为评论发布,但它不支持这么多字符。
SLAks 说你应该学习 VBA 是正确的:)
两个主要优势:
1) 你学习一门新语言
2) 明天如果你得到如果卡住了,您可以自己进行编辑,而不必再次寻求帮助。这也将确保您不必为了解决方案而无休止地等待
您正在使用的代码,我相信最初是由 Dan Evans 编写的,它检查
.Subject
中的“附件”一词以及电子邮件的.Body
,其用途不同,正如您在上面正确提到的那样。对于您的疑问,请参阅以下内容。
提示
使用
item.Attachments.Count
查看是否存在如上面代码所示的附件,然后简单地加密邮件。警告
加密附件不是一个简单的过程。它比普通的 VBA 代码稍微高级一些。因此,请做好大量学习的准备;)
尝试一下,如果您遇到困难,只需发布您尝试过的代码,我们一定会帮助您(即,如果您在学习该语言方面表现出努力):)
HTH
Sid
Mihn, I wanted to post this as a comment but then it wouldn't support so many characters.
SLaks is correct in saying that you should learn VBA :)
TWO MAIN ADVANTAGES:
1) You learn a new language
2) Tomorrow if you get stuck then you can make the edits yourself rather than asking for help again. This will also ensure that you will not have to wait endless hours for a solution
The code that you are using, I believe was written originally by Dan Evans which checks for the word "attachement" in the
.Subject
and the.Body
of the email and serves a different purpose as you have rightly mentioned above.For your query, see the below.
HINT
Use the
item.Attachments.Count
to see if there are attachments as shown in your code above and then simply encrypt the message.CAUTION
Encrypting attachments is not a simple process. It is slightly advanced than normal VBA code. So be prepared for lots of learning ;)
Give it a try and if you are stuck then simply post the code that you tried and we will definitely help you (i.e if you show efforts in learning the language) :)
HTH
Sid