我在VBA for 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
答案 0 :(得分:0)
1)我怎么能这样做,所以Outlook不必让我允许这个宏运行?如何使其成为“可信”的宏。
您可以在Outlook中调整信任中心设置,或者只使用数字签名对宏进行签名。有关详细信息,请参阅Troubleshooting Outlook VBA和Signing your own macros with SelfCert.exe。
2)与同事分享此宏的最佳方式是什么?
VBA宏不是为分发而设计的。所有可能的方式都在To distribute Microsoft Outlook VBA code to other users页面上进行了描述。
相反,我建议改为开发加载项。有关详细信息,请参阅Walkthrough: Creating Your First Application-Level Add-in for Outlook。