首页 文章

如何将相同的回复邮件(Outlook中保存的模板)发送给邮件发件人(to,cc)

提问于
浏览
0

我真正需要的是......我正在接收来自客户(不同客户)的连续邮件,以更新他们在数据库中的资产详细信息..一旦流程完成..我必须回复(包括cc)他们的邮件告诉“资产详细信息成功存储在数据库“(我正在使用模板)...建议我如何使用VBA ...?

选项明确

Public Sub ReplyToAll()

Dim oExp作为Outlook.Explorer

'对于前景中选定的邮件

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

呃:

MsgBox Err.Description, vbCritical

结束子

.......................

第3节

Sub ReplyAll()Dim objOutlookObject as mailItem

对于GetCurrentOutlookItems中的每个objOutlookObject

With objOutlookObject
.ReplyAll.Display

'prob区号不包括保存在位置c中的模板..发生一些错误

.createitemtemplate("c:\car.jtm")

以下一个结束子结束

函数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

结束功能

..........

1 回答

  • 1

    对不起,我的评论非常简短; 500个字符不会给完整答案留下太多空间 .

    你的问题很不清楚,所以很可能会被关闭 . 当然,我看不出有人能回答这个问题 . 这就是为什么您尝试解决自己的问题并根据具体问题返回的重要性 .

    下面我提供了我认为可以帮助您入门的最新帖子的链接 . 正如我在评论中所说,查看最近的帖子 . 使用搜索工具 . 如果你寻找它们,这里有一些非常好的答案 .

    前两篇文章是我写的教程 . 早期的步骤是相同的,但由于问题不完全相同,后面的步骤是不同的 . 看看两者并挑选出与你相关的位 . 其他帖子都包含您可能会发现有用的信息 .

    How to import the outlook mail data to excel

    update excel sheet based on outlook mail

    could anyone guide me in creating an outlook macro that does the following

    send an email from excel 2007 vba using an outlook template set variables

    using visual basic to access subfolder in inbox

    vba outlook event moving email

    New section in response to new information from questioner

    除了稍作修改之外,您问题中的代码来自Microsoft帮助文件 NewMailEx Event . 此代码仅在您具有正确的安装类型并且将其放置在正确的位置时才有效:

    • NewMailEx 事件将仅针对Microsoft Outlook中为收到的邮件(如Microsoft Exchange Server)提供通知的邮箱触发 . 此外,仅当Outlook正在运行时才会触发事件 . 换句话说,它不会触发新项目在Outlook未打开时收到 Inbox . 想要在Exchange服务器电子邮件帐户上运行Outlook的客户访问这些项目的开发人员需要在服务器上实现他们的代码 . 但是, NewMailEx 事件将触发缓存Exchange模式在所有设置中: Download Full ItemsDownload HeadersDownload Headers and then Full Items . “

    你有正确的安装类型吗?你可以把你的代码放在服务器上吗?即使这是宏的最终版本的正确方法,我也不相信这是您学习VBA和Outlook时的正确方法 .

    你需要两件事:

    • 您要编写的宏的详细规范和

    • 更了解VBA和Outlook .

    我怀疑你是否可以创建详细的规范,因为你对VBA和Outlook了解不够 . 但我们可以列出您需要知道的事项:

    • 如何从Outlook写入数据库?

    • 如何识别您要记录的邮件?在您的示例中,您正在检查"Hello"的主题并回复"Hi" . 这适用于第一个实验,但您需要确定真正的方法 . 这是新发件人吗?消息正文中是否有具体信息?人类是否必须识别此类邮件?

    • 在您的示例中,"Inbox"下有一个文件夹"Personal" . 很多人似乎都有这种类型的文件夹结构,而Microsoft的例子往往会使用这样的文件夹 . 我不 . 我有一个名为"!Home"的文件夹 . 在此我有"Insurance","Shopping","Money"的文件夹 . 根据这些,我有不同供应商的文件夹 . 处理完邮件后,我将其移至相应的文件夹中 . 回复转到同一文件夹 . 这是我的系统,它适用于我 . 你的系统是什么?例如,对于所有客户还是每个客户一个文件夹?

    以上是您的规范的问题的入门列表,但它也是您需要知道的事情的入门列表 .

    也许你有一个希望你不要浪费时间并开始编写宏的老板,但是你还不知道计划最终的宏 .

    从我的教程开始 . 前三个步骤是关于文件夹结构 . 如果您拥有我所拥有的复杂文件夹结构,这些步骤是必不可少的 . 接下来,我将浏览显示每个邮件项目中所选信息的文件夹 . 我有一些步骤,我将消息体写入光盘 . 我建议你阅读这两个教程并尝试我的代码 . 并非所有这些都会立即有用,但它们都是很好的背景信息 .

    你的数据库是什么?是Access还是Excel?在我的教程和上面的其他链接中有一些帮助,写入Excel可以适应Access .

    我认为上面的内容已经足够了 . 慢慢来,它会开始有意义 . 我还记得我第一次尝试编写Outlook宏,所以我理解你的困惑 . 我保证会变得清晰 . 祝你好运 .

    New section in response to the following comment:

    • "hello i have tried ..Got what i want....Removed my previous code..and tried replaced the new code .. Now little help needed from you ....is there any way to use same format like when we click the replyall button in outlook .. my code working fine ..prob is format of the mail is differ .."

    Problem 1

    .Body = .Body & Chr(13) & Chr(13)
    

    您正在使用文本正文 . 我想你想要HTML体 . 尝试:

    .HTMLBody = .HTMLBody & Chr(13) & Chr(13)
    

    Problem 2

    您无法以这种方式添加到HTML正文 . HTML正文将是:

    <!doctype ...><html><head> ... </head><body> ... </body></html>
    

    您必须将文本添加到正文的开头;就是在 <body> 之后 . 如果您只是添加文本,您将接受发件人使用的任何样式,边距和颜色 . 以下代码添加了一些在我尝试过的每封电子邮件中看起来相同的文本 . 我的文本在一个包含单个单元格的表格中 . 该表格涵盖了页面的整个宽度 . 文本是蓝色的在白色背景 .

    Dim InsertStg As String
    Dim Inx As Long
    Dim Pos As Long
    
        'Change the body step 1: Create the string to be inserted
        InsertStg = "<table border=0 width=""100%"" style=""Color: #0000FF""" & _
                    " bgColor=#FFFFFF><tr><td><p>"
        For Inx = 1 To 10
          InsertStg = InsertStg & "Sentence " & Inx & " of first paragraph. "
        Next
        InsertStg = InsertStg & "</p><p>"
        For Inx = 1 To 10
          InsertStg = InsertStg & "Sentence " & Inx & " of second paragraph. "
        Next
    
        ' The following adds a signature at the bottom of the message.
        ' "font-family" gives a list of fonts to be tried.  If these are
        ' missing from your computer, use the names of fonts you do have.
        ' "serif" means that if none of the fonts exist any serif font
        ' that exists is to be used.
        InsertStg = InsertStg & "</p><p style = ""font-family: Mistral, " & _
                    "Vivaldi, serif; font-size: 14px; color: " & _
                    "rgb(127,0,127)"">John Smith<br>5 Acacia Avenue<br>"
    
        InsertStg = InsertStg & "</p></td></tr></table>"
        'Change the body step 2: Find insertion position just after <Body> element
        Pos = InStr(1, LCase(.HTMLBody), "<body")
        If Pos = 0 Then
          Call MsgBox("<Body> element not found in HTML body", vbCritical)
          Exit Sub
        End If
        Pos = InStr(Pos, .HTMLBody, ">")
        If Pos = 0 Then
          Call MsgBox("Terminating > for <Body> element not found in HTML body", vbCritical)
          Exit Sub
        End If
        'Change the body step 3: Insert my text into body
        .HTMLBody = Mid(.HTMLBody, 1, Pos) & InsertStg & Mid(.HTMLBody, Pos + 1)
    

相关问题