# VBA code for automatically replying to emails in Outlook 2010



## madmiddle (Jul 11, 2013)

Afternoon gents,

Could i please have some guidance on the following macro.

What i would like it to is reply to the email selected with a personalise template.

Here is the code i have at the moment.

```
Public Sub software_request()
 Dim oMail  As MailItem
 On Error GoTo blad
 Select Case TypeName(Application.ActiveWindow)
        Case "Explorer":  Set oMail = ActiveExplorer.Selection.Item(1)
        Case "Inspector": Set oMail = ActiveInspector.CurrentItem
 Case Else: Exit Sub
 End Select
 Call software_reply(oMail)
blad:
End Sub

Sub software_reply(Item As Outlook.MailItem)
'MVP OShon from VBATools.pl
If Item <> olMailItem = False Then Exit Sub
Dim oReply As MailItem
With Item
    Set oReply = .Reply
         oReply.Body = "Dear " & .SenderName & vbNewLine & _
         "" & vbNewLine & _
         "Your software request has now been submitted " & vbNewLine & _
         "" & vbNewLine & _
         "Regards" & vbNewLine & _
         "" & vbNewLine & _
         "Andy"
         
        oReply.Display
        'oReply.send 'to send
    Set oReply = Nothing
    
End With
End Sub
```

at the moment it comes out like this:


```
[COLOR=#000000][FONT=Arial]Dear Smith, John (UK)
[/FONT][SIZE=3][FONT=Times New Roman] [/FONT][/SIZE][/COLOR]
[COLOR=#000000][FONT=Arial]Your software request has now been submitted [/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]
Regards[/FONT][SIZE=3][FONT=Times New Roman] [/FONT][/SIZE][/COLOR]
[COLOR=#000000][FONT=Arial]
Andy[/FONT][SIZE=3][FONT=Times New Roman] [/FONT][/SIZE][/COLOR]
```

which is nearly there but i would like to include the original message either with it attached or in the email its self.

Also if possible i would only like to have the first name in the 'dear' part if that is possible. 

I'm on Win XP
Outlook 2010 and it's a corporate email system which is probably why it's come up with the (UK) part
and i got the basic code from here

Thank you very much in advance


----------



## dermie_72 (Jul 17, 2013)

see if this is any help:

http://www.mrexcel.com/forum/excel-...ry-lotus-notes-visual-basic-applications.html


----------

