VBA添加附件,文本和签名 [英] VBA To Add Attachment, Text, and Signature
问题描述
您好,在我们的系统中设置新用户时,我会定期向一组用户发送确认回复电子邮件。我正在尝试找到一个VBA脚本,当我准备好这个类型的回复时,我可以运行它。 VBA将1)添加一个Word文件作为附件
到答复2)添加一个文本块3)添加我的Outlook签名。我发现下面的脚本我希望能让我开始,但现在我收到以下错误消息。谁能帮我找到合适的脚本以及帮助处理这个错误?感谢
you。
< blockquote>
您好,
您似乎需要调整信任中心的设置。尝试选择 启用所有宏(不推荐;可能会运行危险代码) in
Macro Settings。不要忘记在进行更改后重新启动Outlook。
> 1)添加一个Word文件作为附件
到答复
添加附件类的方法c 在 附件 collection。 当
an 附件 是
添加到 附件 集合
项目, Type 属性
附件 将
始终返回 olOLE (6)
直到项目被保存。为了确保结果一致,请始终在添加或删除对象中保存项目 附件 collection。
> 2)
添加一个文本块
Outlook对象模型提供了三种处理邮件正文的主要方法:
-
正文。 -
HTMLBody 。 -
Word编辑器.Inspector类提供 WordEditor property
,它从Word对象模型中返回Document类的一个实例,代表邮件正文.Outlook使用Word作为电子邮件编辑器。
您可以在 章
17:使用项目主体 。
> 3)添加我的Outlook签名
如果你在Outlook中创建一个签名,它将保存三个文件( HTM,
TXT和RTF )进入
Vista和Windows 7/8:
C:\ Users \< UserName> \ AppData \ Rooaming\Microsoft \ Signign
您只需要从磁盘中读取相应的文件并将其粘贴到邮件的末尾。
Sub MailWithHTMLSignature()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim SigString As String
Dim Signature As String
Set OutApp = Application
Set OutMail = OutApp.CreateItem(0)
strbody ="< H3>< B>尊敬的客户< / B>< / H3> "& _
"请访问此网站下载新版本。< br>"& _
"如果您遇到问题请与我们联系。< br>" & _
"< A HREF =""""> Page< / A>"& _
"< br>< br>< B>谢谢< / B>"
'只将Mysig.htm更改为您的签名名称
SigString = Environ(" appd ata")& _
" \ Myicoft \Signatures\Mysig.htm"
如果Dir(SigString)<> ""然后
签名= GetBoiler(SigString)
否则
签名=""
结束如果
On Error Resume Next
With OutMail
.To =" eugene@test.com"
.CC =""
.BCC =""
.Subject ="这是主题行"
.HTMLBody = strbody& "<峰; br>" &安培;签名
。发送'或使用.Display
结束时
错误GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
函数GetBoiler(ByVal sFile As String)As String
Dim fso As Object
Dim ts As Object
Set fso = CreateObject(" ; Scripting.FileSystemObject")
设置ts = fso.GetFile(sFile).OpenAsTextStream(1,-2)
GetBoiler = ts.readall
ts.Close
结束函数
请参阅在邮件中插入Outlook签名
更多信息。
Hello, On a regular basis I send a confirmation reply email to a group of users when a new user is setup in our system. I am trying to find a VBA script the I can run when I have this type reply ready to go. The VBA would 1) Add an a Word file as an attachment to the reply 2) Add a a block of text 3) Add my Outlook signature. I found the script below that I hope would get me started, but now I'm getting the below error message. Can anyone help me find an appropriate script as well help dealing with this error? Thank you.
Hello,
It seems you need to adjust settings in the Trust center. Try to choose Enable all macro (not recommended; potentially dangerous code can run) in Macro Settings. Don't forget to restart Outlook after making your changes.
> 1) Add an a Word file as an attachment to the reply
The Add method of the Attachments class creates a new attachment in the Attachments collection. When an Attachment is added to the Attachments collection of an item, the Type property of the Attachment will always return olOLE (6) until the item is saved. To ensure consistent results, always save an item before adding or removing objects in the Attachments collection.
> 2) Add a a block of text
The Outlook object model provides three main ways for dealing with message bodies:
- Body.
- HTMLBody.
- Word editor. The Inspector class provides the WordEditor property which returns an instance of the Document class from the Word object model which represents the message body. Outlook uses Word as an email editor.
You can read more about that in the Chapter 17: Working with Item Bodies .
> 3) Add my Outlook signature
If you create a signature in Outlook it will save three files (HTM, TXT and RTF) into
Vista and Windows 7/8:
C:\Users\<UserName>\AppData\Roaming\Microsoft\SignaturesYou just need to read an appropriate file from the disk and paste it to the end of the message.
Sub MailWithHTMLSignature() Dim OutApp As Object Dim OutMail As Object Dim strbody As String Dim SigString As String Dim Signature As String Set OutApp = Application Set OutMail = OutApp.CreateItem(0) strbody = "<H3><B>Dear Customer</B></H3>" & _ "Please visit this website to download the new version.<br>" & _ "Let me know if you have problems.<br>" & _ "<A HREF=""URL"">Page</A>" & _ "<br><br><B>Thank you</B>" 'Change only Mysig.htm to the name of your signature SigString = Environ("appdata") & _ "\Microsoft\Signatures\Mysig.htm" If Dir(SigString) <> "" Then Signature = GetBoiler(SigString) Else Signature = "" End If On Error Resume Next With OutMail .To = "eugene@test.com" .CC = "" .BCC = "" .Subject = "This is the Subject line" .HTMLBody = strbody & "<br>" & Signature .Send 'or use .Display End With On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing End Sub Function GetBoiler(ByVal sFile As String) As String Dim fso As Object Dim ts As Object Set fso = CreateObject("Scripting.FileSystemObject") Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2) GetBoiler = ts.readall ts.Close End FunctionSee Insert Outlook Signature in mail for more information.
这篇关于VBA添加附件,文本和签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!