VBA Outlook 如何在电子邮件正文中添加超链接 [英] VBA Outlook How to add hyperlink into email body

查看:545
本文介绍了VBA Outlook 如何在电子邮件正文中添加超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此宏为电子邮件添加超链接:

This macro adds hyperlink to email :

  Sub test_add_hyperlink()
     Dim NewMail As Outlook.MailItem
     Set NewMail = Application.ActiveInspector.CurrentItem
     NewMail.HTMLBody = "<HTML><BODY><A href=http://www.someaddress.com>URL_TEXT</A></BODY></HTML>" & NewMail.HTMLBody  End Sub

但是如何在活动光标所在的位置添加超链接?我问是因为我不想在消息的前面添加超链接,而是在我当前编写消息的位置.

but how to add hyperlink in place where active cursor is ? I ask beacause I would like to add hyperlink not at the front of message, but where my currently writing message.

我想添加的超链接是当前复制到Windows剪贴板的文件的超链接,这部分我已经写了,但我不知道如何将它放在电子邮件的前面,但是在活动光标所在的位置.我认为基于宏的 Windows 按键模拟是要遵循的方向之一.

The hyperlink I would like to add is the hyperlink to file which is currently copied to Windows' clipboard, this part I've written, but I can't figure out how to place it not at the front of email, but in place where active cursor is. I think that macro based emulation of Windows' keypressing is one of the directions to follow.

推荐答案

Sub InsertHyperlinkAtCursorPositon()
On Error GoTo finish
strLink = "http://www.outlookcode.com"
strLinkText = "Get Outlook code samples here"
Set objInsp = Application.ActiveInspector
Set objMsg = objInsp.CurrentItem
Set objDoc = objInsp.WordEditor
Set objSel = objDoc.Windows(1).Selection
If objMsg.BodyFormat <> olFormatPlain Then
    objDoc.Hyperlinks.Add objSel.Range, strLink, _
                          "", "", strLinkText, ""
Else
    objSel.InsertAfter strLink
End If
finish:
End Sub

这篇关于VBA Outlook 如何在电子邮件正文中添加超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆