使用excel宏回复Outlook中选定或已打开的邮件

时间:2016-05-02 13:44:20

标签: excel excel-vba email outlook vba

我在excel中创建了一个使用excel envelop创建邮件的代码。但是这段代码会创建一个新的电子邮件,而我想回复在我的Outlook中选择或打开的特定邮件。我想要回复的电子邮件中没有固定的模式,例如特定主题或发件人。所以我想回复/回复只有我在Outlook中选择或打开的邮件。我应该在哪里更改代码?请帮忙!! `

'Option Explicit
Private Sub Generate_Ticket_Email_Click()

'varCap = Generate_Ticket_Email.Caption

'Generate_Ticket_Email.Caption = "DiscardMail"

On Error GoTo ErrHandler


'SET Outlook APPLICATION OBJECT.
Dim objOutlook As Object
Set objOutlook = CreateObject("Outlook.Application")

' CREATE EMAIL OBJECT.
Dim objEmail As Object
Set objEmail = objOutlook.CreateItem(olMailItem)
    ActiveSheet.Range("B7:D31").Select

If Generate_Ticket_Email.Caption <> "Generate E-mail" Then
    Generate_Ticket_Email.Caption = "Generate E-mail"
    ActiveWorkbook.EnvelopeVisible = False
    GoTo ErrHandler
End If


 ActiveWorkbook.EnvelopeVisible = True
'ActiveWorkbook.EnvelopeVisible = False
'End If

With ActiveSheet.MailEnvelope
    .Item.To = Range("J16")
    .Item.CC = Range("J17")
    .Item.Subject = Range("F18")
End With


Generate_Ticket_Email.Caption = "Discard E-mail"

' CLEAR.
Set objEmail = Nothing:    Set objOutlook = Nothing

ErrHandler:

'
End Sub

1 个答案:

答案 0 :(得分:0)

替换

Set objEmail = objOutlook.CreateItem(olMailItem)

Set objEmail = objOutlook.ActiveExplorer.Selection.Item(1).Reply

(省略错误检查)