Solved

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

Posted on 2008-10-30
6
307 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
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
Comment Utility
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
Comment Utility
Yes, indeed. Try it in the way that I suggested in my first comment.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
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…

728 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

11 Experts available now in Live!

Get 1:1 Help Now