我真正需要的是......我正在接收来自客户(不同客户)的连续邮件以更新他们在数据库中的资产详细信息..一旦流程完成..我必须回复(包括cc)他们的邮件告诉“资产详情成功存储在数据库中“(我正在使用模板)...建议我如何使用VBA来做到这一点..?
选项明确
Public Sub ReplyToAll()
Dim oExp As Outlook.Explorer
对于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
错误:
MsgBox Err.Description, vbCritical
End Sub
.......................
第3节
Sub ReplyAll() Dim objOutlookObject as mailItem
对于GetCurrentOutlookItems中的每个objOutlookObject
With objOutlookObject
.ReplyAll.Display
'概率区域代码不包括保存在位置c中的模板。发现一些错误
.createitemtemplate("c:\car.jtm")
结束 下一个 结束子
函数GetCurrentOutlookItems()作为集合 Dim objApp作为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
结束功能
..........
答案 0 :(得分: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
响应来自提问者的新信息的新部分
除了稍作修改外,您问题中的代码来自NewMailEx Event
的Microsoft帮助文件。此代码仅在您具有正确的安装类型并且将其放置在正确的位置时才有效:
您是否拥有正确的安装类型?你可以把你的代码放在服务器上吗?即使这是宏的最终版本的正确方法,我也不相信这是你学习VBA和Outlook时的正确方法。
你需要两件事:
我怀疑你是否可以创建详细的规范,因为你对VBA和Outlook了解不够。但我们可以列出您需要知道的事项:
以上是您的规范的问题的入门列表,但它也是您需要知道的事情的入门列表。
也许你有一个老板,他希望你不要浪费时间并开始编写宏,但你还不知道计划最终的宏。
从我的教程开始。前三个步骤是关于文件夹结构。如果您拥有我所拥有的复杂文件夹结构,这些步骤是必不可少的。接下来,我将浏览显示每个邮件项目中所选信息的文件夹。我有一些步骤,我将消息体写入光盘。我建议你阅读这两个教程并尝试我的代码。并非所有这些都会立即有用,但它们都是很好的背景信息。
你的数据库是什么?是Access还是Excel?在我的教程和上面的其他链接中有一些帮助,可以使用Excel编写,以适应Access。
我认为上面的内容已经足够了。慢慢来,它会开始有意义。我还记得我第一次尝试编写Outlook宏,所以我理解你的困惑。我保证会变得清晰。祝你好运。
回应以下评论的新栏目:
问题1
.Body = .Body & Chr(13) & Chr(13)
您正在使用文本正文。我想你想要HTML体。尝试:
.HTMLBody = .HTMLBody & Chr(13) & Chr(13)
问题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)