【发布时间】:2015-09-25 01:00:21
【问题描述】:
我在 VBA 中为 Outlook 创建了一个宏。我希望在 Outlook 打开时始终启用此宏。
如何才能使 Outlook 不必要求我允许此宏运行?如何使其成为“受信任”宏。
与同事共享此宏的最佳方式是什么?
这是宏脚本,代码运行良好,我正在寻求与我办公室的其他人共享此代码的帮助:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim Recipients As Outlook.Recipients
Dim recip As Outlook.Recipient
Dim i
Dim prompt As String
Dim checklist As String
Dim lbadFound As Boolean
Dim badAddresses As String
lbadFound = False
On Error Resume Next
' use lower case for the address
' LCase converts all addresses in the To field to lower case
' checklist contains the names and email addresses of people involved in the Build Option
checklist = "test@gmail.com"
Set Recipients = Item.Recipients
For i = Recipients.Count To 1 Step -1
Set recip = Recipients.Item(i)
If InStr(1, LCase(checklist), LCase(recip)) >= 1 Then
lbadFound = True
badAddresses = badAddresses & recip & vbCrLf
End If
Next i
If lbadFound Then
prompt$ = "You are sending this email to one or more people on the Build Team: " & vbCrLf & vbCrLf & badAddresses & vbCrLf & " Are you sure you want to send it?"
If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then
Cancel = True
End If
End If
End Sub
【问题讨论】: