Solved

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

Posted on 2008-10-30
6
316 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
[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
  • 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
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…

749 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