Solved

Macro not working properly.

Posted on 2008-10-16
16
972 Views
Last Modified: 2012-05-05
I had a macro written by BlueDevilsFan that appends a string to the end of any email address that I am sending to. It worked great. However, I have found a glitch that has turned out to be very serious. Whenever I send to BCC contacts, and the string is added to those addresses in the BCC field, the addresses are somehow moved into the TO: field after hitting send. I need to know if this can be fixed or else I cant use it. The blind ccs need to stay blind or else it defeats the purpose. Any help would be greatly appreciated.

Here is the macro:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim olkRecipient As Outlook.Recipient, _
        olkNewRecipient As Outlook.Recipient, _
        strAddress As String, _
        intIndex As Integer
    If Item.Class = olMail Then
        For intIndex = Item.Recipients.Count To 1 Step -1
            Set olkRecipient = Item.Recipients(intIndex)
            If InStr(1, olkRecipient.Address, "@") Then
                If Not (InStr(1, LCase(olkRecipient.Address), ".mlxjet.com") > 0) Then
                    strAddress = olkRecipient.Address & ".mlxjet.com"
                    Set olkNewRecipient = Session.CreateRecipient(strAddress)
                    olkNewRecipient.Type = olBCC
                    olkNewRecipient.Type = olkRecipient.Type
                    Item.Recipients.Add olkNewRecipient
                    olkRecipient.Delete
                End If
            End If
        Next
        Item.Save
    End If
    Item.Recipients.ResolveAll
End Sub
0
Comment
Question by:flipside1212
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 8
16 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 210 total points
ID: 22742885
Hi, flipside1212.

Sorry about that.  The code below fixes this.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim olkRecipient As Outlook.Recipient, _
        olkNewRecipient As Outlook.Recipient, _
        strAddress As String, _
        intIndex As Integer
    If Item.Class = olMail Then
        For intIndex = Item.Recipients.Count To 1 Step -1
            Set olkRecipient = Item.Recipients(intIndex)
            If InStr(1, olkRecipient.Address, "@") Then
                If Not (InStr(1, LCase(olkRecipient.Address), ".mlxjet.com") > 0) Then
                    strAddress = olkRecipient.Address & ".mlxjet.com"
                    Set olkNewRecipient = Item.Recipients.Add(strAddress)
                    olkNewRecipient.Type = olBCC
                    olkNewRecipient.Type = olkRecipient.Type
                    olkRecipient.Delete
                End If
            End If
        Next
        Item.Save
    End If
    Item.Recipients.ResolveAll
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:flipside1212
ID: 22743317
Perfect!

I asked you about this before but I don't think I was clear on what the problem was. I have a tendency to muddle things. I've tried this out and it works perfectly. Thank you. Do you ever do contract work?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 22743429
Sorry, if you asked I don't remember.  

Yes, I do contract work occasionally.  That typically depends on the work (i.e. the complexity involved) and how much legal paperwork is involved.  I have a full-time job and don't have a lot of time to devote to outside work, so I shy away from anything too complex.  I also shy away from anything that requires involves much in the way of legal issues.  I'm always willing to discuss a project though.  My email address is in my profile if you want to contact me.
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 1

Author Comment

by:flipside1212
ID: 22743729
I also was wondering if you know if images can be globally enabled within the macro. (Instead of having to go to Tools --> Trust Center --> etc.)
0
 
LVL 76

Expert Comment

by:David Lee
ID: 22743901
Sorry, I don't understand.  What images are you talking about?
0
 
LVL 1

Author Comment

by:flipside1212
ID: 22744131
You know how Outlook blocks automatic download of images by default? Can you write into the macro a function to make it so images aren't blocked. (So you don't have to manually enable images by going throught the menu).
0
 
LVL 76

Expert Comment

by:David Lee
ID: 22744188
Not sure if that's possible or not.  I'll look into it.  You could always add the sender to the "Safe Senders" list.  
0
 
LVL 1

Author Closing Comment

by:flipside1212
ID: 31506918
Great!!!
0
 
LVL 76

Expert Comment

by:David Lee
ID: 22744449
This macro deals with sending items.  Are you asking if there is a way to do something in an item you send that'll cause pictures in your message to be automatically downloaded?  If so, the answer is no.  If that were possible, then there'd be no point to Outlook security since every sender could control downloading images.
0
 
LVL 1

Author Comment

by:flipside1212
ID: 22744553
No, I'm just asking if there is a way to enable images for anyone that uses your macro instead of having them go through the tool menus to manually do it. I'm asking because there are people who want to use this macro you've created to add .mlxjet.com to their emails but it would also be nice if the macro would automatically enable the download of images on the machine that has the macro installed as they have sufficient virus and spam protection in place and would like to generally have emails show up with images.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 22744807
Got it.  I was confused because the macro deals with outbound messages while downloading pictures deals with received messages.  Doing this does not require any code.  The users can change the setting in Outlook.

1.  For Outlook 2003 and earlier: http://office.microsoft.com/en-us/outlook/HP073107391033.aspx
2.  For Outlook 2007: http://office.microsoft.com/en-us/outlook/HP012300401033.aspx?pid=CH100622191033
0
 
LVL 1

Author Comment

by:flipside1212
ID: 22745668
You know, I really appreciate you going the extra miles for my questions but I was asking if it is possible to write this into a macro so that users don't have to manually enable images. In other words, can you write a function into the original macro you gave me that will automatically enable images on incoming messages? I realize that one thing has nothing to do with the other but I thought if the two different functions were installed into the same macro then it would save installation time.

The whole point of my question is this:

I basically don't want the users to have to go through the instructions you gave in the previous post as it may seem easy for us, but it's hard for them. Having it automatically enable global image download would make everyones life really easy!~
0
 
LVL 76

Expert Comment

by:David Lee
ID: 22746261
I know it's just terminology, but a macro is a given SUB or FUNCTION in Outlook.   So, when you initially asked about doing this I'm thinking that you want this additional capability written into that subroutine.  That's why I was confused.  Putting code to change that setting in a block of code that fires every time an item is sent didn't seem to make sense.  Now I understand that when by macro you just meant code.  So, yes, I can write this capability as an additional macro.  The code below does work for Outlook 2003 and 2007.  I'm not sure about other versions.
Sub UnblockPictures()
    Dim objShell As Object, arrVersionInfo As Variant
    arrVersionInfo = Split(Application.Version, ".")
    Set objShell = CreateObject("Wscript.Shell")
    objShell.RegWrite "HKCU\Software\Microsoft\Office\" & arrVersionInfo(0) & ".0\Outlook\Options\Mail\BlockExtContent", 0, "REG_DWORD"
    Set objShell = Nothing
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:flipside1212
ID: 22746850
Wow, sweet! Thank you
0
 
LVL 1

Author Comment

by:flipside1212
ID: 22746888
except, can I just add that after the end of the other macro code? I tried that and it didn't change the setting. I'm sorry, I know nothing about this. if you could tell me how to invoke it that would be awesome!
0
 
LVL 76

Expert Comment

by:David Lee
ID: 22747919
Yes, you can just copy and paste it into Outlook below the code you already have.  To run it, click Tools > Macro > Macros, select it and click the Run button.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
Viewers will learn the different options available in the Backstage view in Excel 2013.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question