Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2008-10-30
6
Medium Priority
?
322 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 77

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 77

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 77

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 77

Accepted Solution

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will help to fix the below errors for MS Exchange Server 2016 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

564 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