从 MS Access 生成带有超链接的电子邮件
Generating Email with Hyperlink from MS Access
当特定过程 运行 并且满足某些条件时,我正在尝试从 MS Access 生成一封电子邮件,该电子邮件将包含一个超链接。我发现 sendobject 宏命令不允许超链接,只允许静态文本。似乎解决方案是在 VBA 中对整个过程中生成和发送电子邮件的部分进行编码,并在我的宏中的 if 函数的适当部分调用该代码。
但是,我想不出合适的代码来生成和发送带有超链接的电子邮件给个人。它将非常简单,单一收件人,不变的标题,并且 body 将显示为 'New providers require designation, please access the provider designation dashboard for provider designation' 理想情况下,提供者指定仪表板将是超链接并指向共享网络 space。
我需要什么命令才能完成此操作,我对 VBA 没有经验,这占用了我没有的大量时间。
谢谢
使用代码发送 e-mail 有一些不同的方法。下面的代码使用 Outlook 应用程序 COM 对象生成带有超链接的消息 - 因此,它仅在用户计算机上安装了 MS Outlook 时才有效。
Sub NewEmail(ByVal mylink As String, ByVal therecipient As String)
Dim Outlook As Object, Email As Object
Set Outlook = CreateObject("Outlook.Application")
Set Email = Outlook.CreateItem(0) 'olMailItem = 0
With Email
.Subject = "My Subject" 'message subject
.HTMLBody = "Greetings, please check this link: <a href='" & mylink & "'>Click me</a>." 'message body, in html. concatenate multiple strings if you need to
.To = therecipient 'recipient
'use this if you want to generate the message and show it to the user
.Display
'use this instead if you want the mail to be sent directly
'.Send
End With
Set Email = Nothing
Set Outlook = Nothing
End Sub
将代码放入模块中。然后在您的代码中的任何地方,您都可以使用以下内容调用该过程:
NewEmail "www.mysite.com/targetpage.html", "persontomail@domain.com"
注意上面的例程使用了late binding。要使用早期绑定(并获得智能化,但有一些缺点),您必须添加对 Microsoft Outlook XX.X 对象库的引用并将 "Outlook" 和 "Email" 对象调暗为 Outlook.Application 和 Outlook.MailItem。
当特定过程 运行 并且满足某些条件时,我正在尝试从 MS Access 生成一封电子邮件,该电子邮件将包含一个超链接。我发现 sendobject 宏命令不允许超链接,只允许静态文本。似乎解决方案是在 VBA 中对整个过程中生成和发送电子邮件的部分进行编码,并在我的宏中的 if 函数的适当部分调用该代码。
但是,我想不出合适的代码来生成和发送带有超链接的电子邮件给个人。它将非常简单,单一收件人,不变的标题,并且 body 将显示为 'New providers require designation, please access the provider designation dashboard for provider designation' 理想情况下,提供者指定仪表板将是超链接并指向共享网络 space。
我需要什么命令才能完成此操作,我对 VBA 没有经验,这占用了我没有的大量时间。
谢谢
使用代码发送 e-mail 有一些不同的方法。下面的代码使用 Outlook 应用程序 COM 对象生成带有超链接的消息 - 因此,它仅在用户计算机上安装了 MS Outlook 时才有效。
Sub NewEmail(ByVal mylink As String, ByVal therecipient As String)
Dim Outlook As Object, Email As Object
Set Outlook = CreateObject("Outlook.Application")
Set Email = Outlook.CreateItem(0) 'olMailItem = 0
With Email
.Subject = "My Subject" 'message subject
.HTMLBody = "Greetings, please check this link: <a href='" & mylink & "'>Click me</a>." 'message body, in html. concatenate multiple strings if you need to
.To = therecipient 'recipient
'use this if you want to generate the message and show it to the user
.Display
'use this instead if you want the mail to be sent directly
'.Send
End With
Set Email = Nothing
Set Outlook = Nothing
End Sub
将代码放入模块中。然后在您的代码中的任何地方,您都可以使用以下内容调用该过程:
NewEmail "www.mysite.com/targetpage.html", "persontomail@domain.com"
注意上面的例程使用了late binding。要使用早期绑定(并获得智能化,但有一些缺点),您必须添加对 Microsoft Outlook XX.X 对象库的引用并将 "Outlook" 和 "Email" 对象调暗为 Outlook.Application 和 Outlook.MailItem。