andrewrmunro
andrewrmunro

Reputation: 63

How to share Outlook VBA

I have created a macro in VBA for Outlook. I want this macro to be enabled all the time when Outlook is open.

  1. How can I make it so Outlook does not have to ask me to allow this macro to run? How do I make it a 'trusted' macro.

  2. What is the best way to share this macro with colleagues?

Here is the macro script, the code works fine, I am looking for help on sharing this with other in my office:

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 = "[email protected]" 

 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

Upvotes: 4

Views: 4003

Answers (1)

Eugene Astafiev
Eugene Astafiev

Reputation: 49455

1) How can I make it so Outlook does not have to ask me to allow this macro to run? How do I make it a 'trusted' macro.

You may adjust the Trust Center settings in Outlook or just sign macros with a digital signature. See Troubleshooting Outlook VBA and Signing your own macros with SelfCert.exe for more information.

2) What is the best way to share this macro with colleagues?

VBA macros are not designed for distribution. All possible ways are described on the To distribute Microsoft Outlook VBA code to other users page.

Instead, I'd suggest developing an add-in instead. See Walkthrough: Creating Your First Application-Level Add-in for Outlook for more information.

Upvotes: 2

Related Questions