如何通过Excel VBA在Outlook中自动化回复



我正在尝试使用一个程序,可以在其中使用Excel VBA在Outlook中回复选定的电子邮件。不幸的是,我找不到任何工作代码。

Option Explicit
Sub ReplyMSG()
  Dim olItem As Outlook.MailItem
  Dim olReply As MailItem ' Reply
  Dim olRecip As Recipient ' Add Recipient
  Dim myOlExp As Outlook.Explorer
  Dim myOlSel As Outlook.Selection
  Set myOlExp = Application.ActiveExplorer
  Set myOlSel = myOlExp.Selection
  For Each olItem In myOlSel
  Set olReply = olItem.ReplyAll
  Set olRecip = olReply.Recipients.Add("Email Address Here") ' Recipient Address
    olRecip.Type = olCC
        olReply.HTMLBody = "Hello, Thank you. " & vbCrLf & olReply.HTMLBody
    olReply.Display
    'olReply.Send
  Next olItem
End Sub

我正在尝试使用此代码,但是错误438对象不支持此属性或方法不断出现。希望在此自动化方面获得帮助。

如果您在Excel VBA中写作,则该术语应用程序适用于Excel。Excel应用程序没有ActiveExplorer属性。您应该挂回您在提供的代码中看不到的Outlook应用程序,例如SET myOlExp = refToOutlookApplication.ActiveExplorer

查看您上面显示的内容:

Set myOlExp = Application.ActiveExplorer

这意味着Set myOlExp = Excel.Application.ActiveExplorer,事实是Excel应用程序没有Explorer对象。

所以您需要:Set myOlExp = refToOutlookApplication.ActiveExplorer

您需要明确说明您希望为Outlook应用程序的属性分配一个变量 - 在此阶段,我将假设您已经在模块中的其他Earlie中创建了一个参考。

如果没有,那么您需要使用:

Dim refToOutlookApplication As Object    'Outlook.Application
Set refToOutlookApplication = GetObject(, "Outlook.Application")

最新更新