Solved

How do I combine these macros so they load with Outlook startup?

Posted on 2008-10-30
6
314 Views
Last Modified: 2012-06-21
I would like to know how I can combine these two macros so that they open automatically on Outlook startup (providing the user clicks enable - The security is set to ask). And I would like it so that the second part of this macro doesn't run again if it has already changed the registry info that it was supposed to the first time it is ran.

Here is the code I'm talking about:

Macro 1:

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


Macro 2 (I would like this part to be added to macro 1 so that it runs once, if what it does has not been done yet):

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

0
Comment
Question by:flipside1212
  • 4
  • 2
6 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 22846171
It isn't clear what you mean by 'combine'.

The first should be in the ThisOutlookSession module and will run whenever a message is sent. It needs to input parameter to know what is being sent, so it can't be run at start up.

The second can be run at start up. Put it in the ThisOutlookSession module as well. You can call it from the Application_Startup Sub, so:
Private Sub Application_Startup()
    UnblockPictures
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:flipside1212
ID: 22846192
Sorry, I don't quite understand. I put the first macro in ThisOutlookSession so that it runs when I start Outlook, and I want to put the second one within the first one so that it will also execute when I start Outlook, but ideally only if it hasn't been executed already, unless it doesn't really matter if it keeps executing every time I start Outlook.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 22846198
There will be little difference between running the second macro unnecessarily, and running one which tests to see if it has been done and only then running it.
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 76

Expert Comment

by:GrahamSkan
ID: 22846917
You cannot run the first macro without the input parameters. One of the parameters refers to the mail item which is being sent. Therefore it only makes sense to a call it when an item is being sent. It will do that if the code is in the ThisOutLookSession module.

The other macro can be run at Outlook startup in the way that I described.

You can also call it from within the first macro if you wish, so that it will run every time that an item is sent.

I do not understand why you would want to do it when you send, so I don't know if you need it before or after the other code in the module, but you could do it like 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
 
    UnblockPictures '<-----------------
 
    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: 22848056
Sorry, you're right. I just want #2 to run at startup of Outlook and #1 to run when the item is sent. Can I still put it in the way you described?
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 75 total points
ID: 22848307
Yes, indeed. Try it in the way that I suggested in my first comment.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using Outlook for iOS securely 2 44
Outlook 2010 not responding 14 44
One Drive Login/Configuration Issue 12 43
Outlook 2013 sent view customization 2 23
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
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).
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

772 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