Solved

Macro not working properly.

Posted on 2008-10-16
16
961 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
  • 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
 
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now