none
VBA ThisOutlookSession not working RRS feed

  • General discussion

  • I have been using the below VBA code for a few years now to automatically BCC myself in emails I send from Outlook. I've not had any problems with this code until now. I've started a new job in a new company and the code just isn't running. My security settings are low enough for this so I'm not sure what is stopping it. Would anyone have any thoughts?

    Thanks!

    Private Sub Application_ItemSend(ByVal Item As Object, _
                                     Cancel As Boolean)
        Dim objRecip As Recipient
        Dim strMsg As String
        Dim res As Integer
        Dim strBcc As String
        On Error Resume Next
     
        ' #### USER OPTIONS ####
        ' email
        ' or resolvable to a name in the address book
        strBcc = "email"
     
        Set objRecip = Item.Recipients.Add(strBcc)
        objRecip.Type = olBCC
        If Not objRecip.Resolve Then
            strMsg = "Could not resolve the Bcc recipient. " & _
                     "Do you want to send the message?"
            res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
                    "Could Not Resolve Bcc")
            If res = vbNo Then
                Cancel = True
            End If
        End If
     
        Set objRecip = Nothing



    Tuesday, March 24, 2015 11:48 AM

All replies

  • Hello Elli,

    Did you copy the code to the new PC?

    It looks like you forgot to to paste the following statement in the code - End Sub. For example:

    Private Sub Application_ItemSend(ByVal Item As Object, _
                                      Cancel As Boolean)
         Dim objRecip As Recipient
         Dim strMsg As String
         Dim res As Integer
         Dim strBcc As String
         On Error Resume Next
      
         ' #### USER OPTIONS ####
         ' or resolvable to a name in the address book
         strBcc = "Eleanor.Coates@technicolor.com"
      
         Set objRecip = Item.Recipients.Add(strBcc)
         objRecip.Type = olBCC
         If Not objRecip.Resolve Then
             strMsg = "Could not resolve the Bcc recipient. " & _
                      "Do you want to send the message?"
             res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
                     "Could Not Resolve Bcc")
             If res = vbNo Then
                 Cancel = True
             End If
         End If
      
         Set objRecip = Nothing 
    End Sub

    Also in the VBA editor select the Application entry in the left-hand side combo box. On the right choose the ItemSend event. The event handler sub will be generated automatically for you.

    Finally, you may find the Getting Started with VBA in Outlook 2010 article helpful.


    • Edited by Eugene Astafiev Wednesday, March 25, 2015 10:07 AM removed the email address
    Tuesday, March 24, 2015 12:16 PM
  • Hi,

    That was a copy mistake here, End Sub is there in Outlook. And I do have ItemSend as the event.

    I'll have a read of the stuff on that link though.

    Thanks!

    Tuesday, March 24, 2015 3:20 PM
  • Are you able to run any VBA sub manually?
    Tuesday, March 24, 2015 3:24 PM
  • Hi ElliRayne,

    Do you mean that event not trigger?

    Did you try with other event?

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 25, 2015 7:45 AM
    Moderator
  • Hi,

    All good, I have got it working now :)

    Thanks!

    Wednesday, March 25, 2015 9:05 AM
  • Hiya,

    Any chance you could please edit your response to remove my email address now?

    Thanks again for your help!

    E

    Wednesday, March 25, 2015 9:06 AM
  • Hi Elli,

    Sure ;-) I just copied the source code from the initial post. 

    Wednesday, March 25, 2015 10:06 AM
  • Hi ElliRayne,

    Could you share your solution here, which will benefit others who has the similar issue?

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 26, 2015 2:48 AM
    Moderator
  • Hi,

    It was an internal security measure unfortunately so I can't provide an answer for others who have the same issue.

    Thanks,

    E

    Thursday, March 26, 2015 10:07 AM
  • One of them is still there... :P
    Thursday, March 26, 2015 10:09 AM
  • Due to the Trust Center settings in Outlook?
    Thursday, March 26, 2015 10:20 AM