3
votes

I created a VBA script in Outlook 2010 but the only way it will run is by clicking on the play button while in Outlook VBA as indicated in the image below:

VBA

Why won't it run when I select the VBA script from the menu as indicated in the image below? I have already signed the VBA script by using "SelfCert.exe".

macro menu

The other two VBA scripts in the list do run when they are selected from the menu. Below is the code of the VBA script that does not run:

Sub ReplaceIPs()
    Dim Insp As Inspector
    Dim obj As Object

    Set Insp = Application.ActiveInspector
    Set obj = Insp.CurrentItem

    obj.HTMLBody = Replace(obj.HTMLBody, "192.168.1", "255.255.255")

    Set obj = Nothing
    Set Insp = Nothing
End Sub

The above VBA script is supposed to find and replace all instances of "192.168.1" with "255.255.255" in the body of the email that is being composed.

2
What happens if you put 192.168.1 into the body of your message and then run your macro? I tried your code here and it did work. This will not replace IP addresses in the header of an emailMichael Petch
I do add 192.168.1 in the body. That's how I test it but it does not work. Did you add the code as a module in VBA?Jeff
Yes I did. See my answer and see if that resolves your problem.Michael Petch

2 Answers

3
votes

A Module name can't contain a Macro of the same name. Rename the module ReplaceIPs to something else or rename the macro/subroutine ReplaceIPs with something else. If they are both the same it won't resolve properly

1
votes

In case it helps anyone, none of the methods in my Outlook VBA module were getting control, because the entire module was failing to pre-compile, because I had an extra "." in front of a "Sub" stmt

Trying to run an arbitrary method ("F8") showed the problem.