2
votes

I've been trying to improve the "quality of life" for a follow-up email process in the office with a userform+vba snippet, and I've hit a roadblock in that while I've been able to create a brand new email and format it with all the good stuff like .Body, .Attachments.Add, .To, etc., I haven't been able to figure out how to reply to an already-existing email, which is a necessary part of this follow-up process.

I saw this SO page that gave a solution for C#/vb.net, and in using the Object Browser I found that a "Application.ActiveExplorer" exists in VBA as well. This is what I'm currently working with:

Private Sub btnSubmit_Click()
Dim msg As String
Dim objMsg As Outlook.MailItem

Set followUp = objMsg.ActiveInspector.CurrentItem
With followUp

' Compose message
msg = "Good Morning," & "<br />" & "<br />"
msg = msg & "This is a follow-up request for the following outstanding subjectivities: " & "<br />" & "<br />"

For i = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(i) Then
    Counter = Counter + 1
msg = msg & ListBox1.List(i) & "<br />"

Else: If Counter = 0 Then msg = msg & “nothing”
End If
Next

msg = msg & "<br />" & "If these are not submitted within 3 days, a Notice of Cancellation will be sent." & _
"Please let us know if you have any questions or concerns." & "<br />" & "<br />"

    .Reply
    .HTMLBody = msg
    ' .Attachments.Add (" ")
    Unload subjectivitiesSelection
    .Display
End With 
End Sub

The end goal is just to populate a response message so the user can just append the appropriate user signature and send it off, nothing fancy or automated but something that just makes life a little easier and working a little faster. I've got other things to address in this project (example: hitting OK without selecting any of the predetermined factors would probably still build the email regardless) as I go on but this is probably the biggest obstacle in my path.

I apologize if this isn't up to standards or if there's anything missing/unclear, I'm just yet another novice looking for some direction; been learning this as I go with the Object Explorer, MSDN, and plain old searching. I'll try to clarify whatever I can if there's anything ambiguous.

Thanks for your time.

1

1 Answers

0
votes

Use MailItem.Reply method - it returns the newly created MailItem object. Your code above does not make much sense - objMsg variable is not initialized and MailItem object does not have the ActiveInspector property, but the Application object does. You might also want to look at the Application.ActiveExplorer.Selection collection: it will contain the currently selected items in the folder. Application.ActiveInspector is only for the messages opened in the active inspector.