VBA Macro - Run-time error '424': object required - Help Please

Status
Not open for further replies.

Steve Tomalin

Member
Outlook version
Outlook 2016 32 bit
Email Account
Outlook.com (as MS Exchange)
Hi,

I'm afraid I'm no developer, but I'm trying to cobble together a small automation solution in Outlook for myself, using some example code I found on the web (which originated from Sue Mosher), but I'm afraid I've stumbled at the very first hurdle.

I want to get Outlook to 'do something' within the current, open email form, each time I create a new email, or perform Reply, or Reply All, or Forward on an existing email. At this point, I don't think the 'something' is important, I'm hitting my problem before even getting that far! Here is my code, as it stands:

Dim WithEvents colInsp As Outlook.Inspectors

Private Sub Application_Startup()
Set colInsp = Application.Inspectors
End Sub

Private Sub colInsp_NewInspector(ByVal Inspector As Inspector)
Dim objMail As Outlook.MailItem
If Inspector.CurrentItem.Class = olMail Then
Set objMail = Inspector.CurrentItem.Class
If objMail.Sent = False Then
MsgBox "Hello World", vbOKOnly, "Debug Message"
End If
End If
Set objMail = Nothing
End Sub

I replaced an original line from the example code with the line:
MsgBox "Hello World", vbOKOnly, "Debug Message"

I did this on the expectation that when I clicked New Email, or Reply etc., the email form would open and I'd then see the message box, just to prove to myself that the macro would execute as I was hoping/expected.

The macro certainly seems to begin to execute when I create a new email or begin a reply, but it fails at the line:
Set objMail = Inspector.CurrentItem.Class

The error message is:
Run-time error '424': object required

It would seem that the eror is occurring before the line I replaced, so I'm thinking that my line is not the problem here. I'm using Outlook 2016, so I wonder if there might be a compatibility issue with the code, which probably predates this version? If that's not it, then I'm wondering if maybe I've simply not created the macro within Outlook in the correct way, or in the correct location, or with the correct properties, or something like that?

If anyone could provide me with some assistance here, I'd be very grateful. I think that once I have the basic functionality working, I'm hoping I will be able to create the rest of the macro (which will do the thing I want it to do) without needing any further assistance. Many thanks, in advance.

Kind regards,

Steve
 
Hi Diane,

Brilliant, it works! Makes me wonder why that '.Class' was in the original example, but I guess it could just have been a typo.

Anyway, many thanks indeed for your help, I can now get on with trying to acheive the primary objective!

Kind regards,

Steve
 
Year, most likely a typo or they copied it from the line above and forgot to remove it - i've done that before. :(
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
P Vba script including macro appears in rules but wont run Outlook VBA and Custom Forms 6
M Run external program from Outlook VBA macro Outlook VBA and Custom Forms 5
D VBA Macro to Print and Save email to network location Outlook VBA and Custom Forms 1
N VBA Macro To Save Emails Outlook VBA and Custom Forms 1
N Help creating a VBA macro with conditional formatting to change the font color of all external emails to red Outlook VBA and Custom Forms 5
L Modifying VBA script to delay running macro Outlook VBA and Custom Forms 3
L Macro/VBA to Reply All, with the original attachments Outlook VBA and Custom Forms 2
A VBA macro for 15 second loop in send and received just for 1 specific mailbox Outlook VBA and Custom Forms 1
G VBA Macro Using Outlook 4
R Help Revising VBA macro to delete email over different time span Outlook VBA and Custom Forms 0
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
N How can I increase/faster outlook VBA Macro Speed ? Using Outlook 2
D.Moore Folder view settings by VBA macro Outlook VBA and Custom Forms 57
J Help Please!!! Outlook 2016 - VBA Macro for replying with attachment in meeting invite Outlook VBA and Custom Forms 9
R VBA macro - new message Outlook VBA and Custom Forms 3
S Example VBA Macro - To Conditionally Change the From Account and Add a BCC Address on Emails Outlook VBA and Custom Forms 11
B VBA Macro for assigning multiple Categories to an email in my Inbox Outlook VBA and Custom Forms 1
M Slow VBA macro in Outlook Outlook VBA and Custom Forms 5
M VBA macro for Inbox's attachments search Outlook VBA and Custom Forms 0
Y VBA Macro to highlight some Keyword in mail body? Outlook VBA and Custom Forms 3
J Macro only runs within VBA Editor Outlook VBA and Custom Forms 2
D VBA macro printing attachments in shared mailbox Outlook VBA and Custom Forms 1
G VBA/Macro to remove page colour when replying or forwarding email Outlook VBA and Custom Forms 2
S Outlook 7 VBA macro for multiple filing Outlook VBA and Custom Forms 1
M Outlook VBA Macro that could retrieve/display the (From, Subject, Date Received) Outlook VBA and Custom Forms 2
Philip Rose Recreating a WORD Editing Macro to use in Outlook VBA Outlook VBA and Custom Forms 4
T Random problem in VBA macro Outlook VBA and Custom Forms 6
M recover deleted items vba macro Outlook VBA and Custom Forms 2
S VBA Macro to VBScript Outlook VBA and Custom Forms 1
L VBA Macro to flag sent emails Using Outlook 1
B Outlook vba macro Using Outlook 1
B Auto BCC VBA macro: how to add exceptions? Using Outlook 28
R VBA Macro to VBScript in a form- Help Please! Using Outlook 10
D VBA Macro Works in 2007 but errors in 2010 Using Outlook 2
E Word macro running from OL VBA throwing error on Word SaveAs?? Outlook VBA and Custom Forms 8
J Outlook custom form - VBS call VBA macro Outlook VBA and Custom Forms 3
N VBA Procedure (or Macro) to Stop Outlook from Closing? Outlook VBA and Custom Forms 2
D New Macro / VBA Outlook VBA and Custom Forms 7
J Specify Font Name or Face using VBA Macro in Word Outlook VBA and Custom Forms 2
S Custom VBA forms in Outlook--how to call w/macro? Outlook VBA and Custom Forms 1
S macro ist just worling wenn vba editor is open! Outlook VBA and Custom Forms 1
H using VBA to edit subject line Outlook VBA and Custom Forms 0
G Get current open draft message body from VBA Outlook VBA and Custom Forms 1
Geldner Problem submitting SPAM using Outlook VBA Form Outlook VBA and Custom Forms 2
P VBA to add email address to Outlook 365 rule Outlook VBA and Custom Forms 0
M Outlook 2016 outlook vba to look into shared mailbox Outlook VBA and Custom Forms 0
V VBA Categories unrelated to visible calendar and Visual appointment Categories Outlook VBA and Custom Forms 2
D Outlook VBA forward the selected email to the original sender’s email ID (including the email used in TO, CC Field) from the email chain Outlook VBA and Custom Forms 2
R Outlook 365 VBA AUTO SEND WITH DELAY FOR EACH EMAIL Outlook VBA and Custom Forms 0
R Outlook 2019 VBA to List Meetings in Rooms Outlook VBA and Custom Forms 0

Similar threads

Back
Top