【发布时间】:2012-02-07 14:53:46
【问题描述】:
我不断收到来自客户(不同客户)的电子邮件,以更新他们在数据库中的资产详细信息。处理完成后..我必须从他们的邮件中回复(包括抄送),如“资产详细信息已成功存储在数据库中”(我正在使用模板)使用 VBA。
Option Explicit
Public Sub ReplyToAll()
Dim oExp As Outlook.Explorer
'for selected mails in outlook
Dim oSM As mailItem
Dim oNM As mailItem
On Error GoTo Err
Set oExp = Outlook.Application.ActiveExplorer
'Check if something is selected
If oExp.Selection.Count > 0 Then
'Get the first item selected
Set oSM = ActiveExplorer.Selection.Item(1)
'Create a Reply template
Set oNM = oSM.ReplyAll
With oNM
'Change the subject
.Subject = "RE: " & oSM.Subject
'Change the body
.Body = .Body & Chr(13) & Chr(13)
'Display the new mail before sending it
.Display
End With
End If
Exit Sub
Err:
MsgBox Err.Description, vbCritical
End Sub
第 3 节
Sub ReplyAll()
Dim objOutlookObject As mailItem
For Each objOutlookObject In GetCurrentOutlookItems
With objOutlookObject
.ReplyAll.Display
'prob area code does not include the template saved in the location c ..throws some error
.createitemtemplate("c:\car.jtm")
End With
Next
End Sub
Function GetCurrentOutlookItems() As Collection
Dim objApp As Outlook.Application
Dim objItem As Object
Dim colItems As New Collection
Set objApp = CreateObject("Outlook.Application")
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
For Each objItem In objApp.ActiveExplorer.Selection
colItems.Add objItem
Next
Case "Inspector"
colItems.Add objApp.ActiveInspector.CurrentItem
Case Else
' anything else will result in an error, which is
' why we have the error handler above
End Select
Set objApp = Nothing
Set GetCurrentOutlookItems = colItems
End Function
【问题讨论】:
-
查看上个月的
outlook-vba问题。有几个解释了您的问题的不同方面:如何访问邮件项目、如何提取详细信息以及如何自动回复。您没有告诉我们有关您的数据库的任何信息,因此没有人可以帮助您。根据最近的答案构建一个宏,如果该宏不起作用,则返回一个特定的问题。 -
我搜索了我能找到相关的东西..你能建议任何帖子..如何从原始邮件发送回复,以便我可以开发我的宏..
-
同意托尼的观点。您需要提出具体的问题并展示您的尝试。
-
上面我已经给出了代码和它显示的输出......以及我需要什么......谢谢你的建议:)
标签: vba outlook outlook-addin outlook-2007