Outlook 2010 VBA issue

Status
Not open for further replies.

litestream

Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
I am using the VBA below to autoreply to an email from the Inbox in Outlook 2010 when a button is clicked on the ribbon.

Everything works fine unless the command button is accidentally clicked twice, when the opened reply window is moved behind Outlook and an error message 800200009 is generated. I put in some error handling for this and the error 424 which occurred afterwards.

The error handling seems to work ok, except that I want the reply window generated from VBA to come to the front of Outlook.

Can anyone help with this please.

Here is my code:

Public Sub ReplyCurrentMsgEng()

On Error GoTo ErrorHandler
Const TEXT_FILE_PATH As String = "\\AutoreplyTemplates\autoreply_Eng.html"
Dim obj As Object
Dim msg As Outlook.MailItem
Dim msgReply As Outlook.MailItem
Dim fileNum As Integer
Dim fileContents As String
Set obj = GetCurrentItem
If TypeName(obj) = "MailItem" Then
Set msg = obj
Set msgReply = msg.Reply
fileNum = FreeFile
Open TEXT_FILE_PATH For Input As #fileNum
fileContents = Input$(LOF(fileNum), 1)
Close #fileNum
With msgReply
.Subject = "Reply from Customer Service Team"
.BodyFormat = olFormatHTML
.HTMLBody = fileContents
.Display
End With
End If

ProcedureDone:

Exit Sub

ErrorHandler:

Select Case Err.Number

Case 800200009

Exit Sub

Case 424

Exit Sub

'Case Else

'All outstanding errors

'MsgBox Err.Number & ": " & Error.Description

End Select

Resume ProcedureDone

End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Hmmm. Here it goes through the macro twice, the first time hitting the error handler, the second time creating the message. If i remove the error handler, it stops on the second time through because it can't reply to the reply....

I switch the one error line to
On Error GoTo ProcedureDone

and removed the errorhandler, using these lines at the end:
Exit Sub ' exits when the macro works

ProcedureDone:
MsgBox "You need to select a received message"

The 424 object required error is because this fails to set an object:

Set msg = obj

Set msgReply = msg.Reply
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
dweller Outlook 2010 Rule Ignores VBA Script Outlook VBA and Custom Forms 2
D create an html table in outlook custom form 2010 using vba in MsAccess Outlook VBA and Custom Forms 7
D Change sender name outlook vba 2010 Custom Userform Outlook VBA and Custom Forms 1
N VBA Script to Send Automatic Emails from Outlook 2010 Outlook VBA and Custom Forms 1
G Outlook 2010 VBA Coding Assistance please! Outlook VBA and Custom Forms 5
G Outlook 2003 VBA Won't Run In Outlook 2010 Outlook VBA and Custom Forms 4
R How to copy outlook 2010 shared calendar appointment or meeting to personal calendar by vba? Outlook VBA and Custom Forms 1
M VBA code needed to move from Outlook 2010 subfolder to Symantec Vault subfolde Using Outlook 0
B Excel 2010 vba to post appts to different outlook calendars at the same time Using Outlook 6
M Updating VBA code from outlook 2007 to outlook 2010 Using Outlook 1
e_a_g_l_e_p_i Can emails from Gmail be deleted when they are downloaded to Outlook 2010 Using Outlook 1
L Outlook 2010 Outlook 2010 Outlook VBA and Custom Forms 2
C What folders are needed when reinstalling Outlook 2010 Using Outlook 0
e_a_g_l_e_p_i Gmail in Outlook 2010 preview issue Using Outlook 4
e_a_g_l_e_p_i Outlook 2010 Help setting up Gmail account in Outlook 2010 Using Outlook 3
B Outlook 2016 Unable to view images or logos on the outlook 2016 emails the same html code works well when i use outlook 2010 Using Outlook 0
M Outlook 2010 Outlook 2010 with O365 / Exchange Online Using Outlook 0
F Outlook 2010 Outlook 2010 and GMail Using Outlook 0
D Outlook 2007 vs. Outlook 2010 -- ToDo Bar Using Outlook 0
e_a_g_l_e_p_i I think it may be time to upgrade from Outlook 2010 Using Outlook 3
T Why does outlook 2010 convert only some forum notifications to plain text? Using Outlook 0
I Error saving screenshots in a custom form in outlook 2016, outlook 365 - ok in outlook 2013, outlook 2010 Outlook VBA and Custom Forms 5
M Outlook 2010 Problem with OutLook 2010 32 bit, after Windows Auto Update Using Outlook 3
M PST import from Outlook 2007 to 2010 - Address Book contacts all in 1 group Using Outlook 4
D Outlook 2010 account setup fails in particular domain Using Outlook 3
B Outlook 2010 is Auto Purging when not configured for that Using Outlook 1
W Outlook 2010 Reading Pane Slows Startup Using Outlook 3
S Outlook 2010 unable to change default font Using Outlook 7
B Outlook 2010 Can not find a certain file in M/S Outlook 2010. Using Outlook 1
Mark Foley Cannot enable add-in in outlook 2010 Using Outlook 0
W Outlook 2010 some sent items marked unread now (was Ok before) Using Outlook 0
RBLampert Updating from Outlook 2010 to Outlook 365 Using Outlook 0
L What are the risks of opening an Outlook 2016 .pst file in Outlook 2010? Using Outlook 4
S Unable to remove rule outlook 2010 Using Outlook 0
N Outlook 2010 Flag blocked for Safe Senders List???? Using Outlook 7
Mark Foley Unable to subscribe to published calendar in Outlook 2010 Using Outlook 4
K Maximum Categorize Shortcuts In Outlook 2010? Using Outlook 1
E Unable to open Outlook 2010 after adding new email account Using Outlook 4
RBLampert Outlook 2010 no longer (?) shrinks large images Using Outlook 4
N Outlook 2010 will not send nor receive Using Outlook 4
U Outlook 2010 'freezes' before moving emails Using Outlook 2
P Outlook 2010 trusted emails going to spam folder Using Outlook 18
E Outlook 2010 Subject sort uses Thread-Topic for grouping Using Outlook 2
King Mustard Maximum Categorize shortcuts in Outlook 2010? Using Outlook 1
C Outlook 2010 keeps asking for username and password Using Outlook 1
M Duplicate Primary Mail Accounts outlook 2010 Using Outlook 0
T Compacting Outlook 2010 OST results in old emails being re-sent Using Outlook 6
K Outlook 2010 duplicate download emails 1 inbox 1 PST no updates Using Outlook 3
Potty Ash MS Outlook 2010 custom form - validation or formula to request user to check a checkbox Outlook VBA and Custom Forms 16
RBLampert Outlook 2010 sends to/receives from some Gmail addresses but not others Using Outlook 3

Similar threads

Top