gpt4 book ai didi

excel - 如何在电子邮件正文中插入超链接

转载 作者:行者123 更新时间:2023-12-03 03:27:18 30 4
gpt4 key购买 nike

我在 Excel 中创建了一个宏,以便在每次更新特定文件时向各个用户发送电子邮件。

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Dim answer As String

answer = MsgBox("Would you like to save the changes?", vbYesNo, "Save Document")

If answer = vbNo Then Cancel = True

If answer = vbYes Then
'open outlook type stuff
Set OutlookApp = CreateObject("Outlook.Application")
Set OlObjects = OutlookApp.GetNamespace("MAPI")
Set newmsg = OutlookApp.CreateItem(olMailItem)
'add recipients
'newmsg.Recipients.Add ("Name1")
newmsg.Recipients.Add ("email@xxx.com")
'newmsg.Recipients.Add ("Name2")
newmsg.Recipients.Add ("email@xxx.com")
'add subject
newmsg.Subject = "Notification - Update file"
'add body
newmsg.Body = "This is an automated notification." & vbNewLine & vbNewLine & _
"The XXX file has been recently updated" & vbNewLine & vbNewLine & _
"Please do not reply to this email."
newmsg.Display 'display
newmsg.Send 'send message
'give conformation of sent message
MsgBox "Your document has successfully been saved", , "Confirmation"
End If

'save the document
'Me.Worksheets.Save

End Sub

我想在正文中添加一个超链接,其中显示“XXX 文件最近已更新”,以便XXX 文件成为指向网站。

最佳答案

Outlook 对象模型支持三种主要的自定义邮件正文的方式:

  1. Body属性返回或设置表示 Outlook 项目的明文正文的字符串。
  2. HTMLBody MailItem 类的属性返回或设置表示指定项目的 HTML 正文的字符串。设置 HTMLBody 属性将始终立即更新 Body 属性。例如:
     Sub CreateHTMLMail() 
'Creates a new e-mail item and modifies its properties.
Dim objMail As Outlook.MailItem
'Create e-mail item
Set objMail = Application.CreateItem(olMailItem)
With objMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.HTMLBody = "<HTML><BODY>Enter the message <a href="http://google.com">text</a> here. </BODY></HTML>"
.Display
End With
End Sub
  • Word 对象模型可用于处理消息正文。请参阅Chapter 17: Working with Item Bodies了解更多信息。
  • 注意,MailItem.BodyFormat属性允许您以编程方式更改用于项目正文的编辑器。

    最后两个支持在消息正文中创建超链接。选择哪种方式取决于您。

    关于excel - 如何在电子邮件正文中插入超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46736021/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com