【问题标题】:Insert a link to an Outlook email within Excel在 Excel 中插入 Outlook 电子邮件的链接
【发布时间】:2017-10-21 03:45:17
【问题描述】:

我正在尝试在 Excel 单元格中创建指向现有 Outlook 电子邮件的超链接。

用户应该能够单击单元格中的链接(也可以是带有 VBA 代码的按钮)以打开电子邮件。

我知道 pst 文件必须在 Outlook 中打开(?),所以我们假设 Outlook 正在运行并且相关 pst 文件已经打开。

我没有找到任何可点击的方式来打开电子邮件。

【问题讨论】:

  • 并打开引用的电子邮件。那是什么引用?还是静态的还是动态的?
  • Excel 单元格中的链接将指向特定的电子邮件,以便 Excel 用户可以单击该链接并在 Outlook 中打开该电子邮件。电子邮件将在 pst 文件中处于静态位置。我不确定这是否回答了你的问题?此 Excel 表将用于指向他们收到的采购订单的供应商确认电子邮件。

标签: excel vba email hyperlink outlook


【解决方案1】:

我不太确定我是否理解全部内容,但您可以尝试以下方法:

Sub OpenMessage()
    Dim wb As Workbook, ws As Worksheet
    Dim mailOL As Outlook.Application, mailItems As Outlook.Items
    Dim mailFolder As Outlook.MAPIFolder, mail As Object

    Set wb = ActiveWorkbook
    Set ws = Sheets("Sheet1")

    Set mailOL = Outlook.Application
    Set mailFolder = mailOL.ActiveExplorer.CurrentFolder
    Set mailItems = mailFolder.Items

    For Each mail In mailItems 'search Cell A1 value among email subjects
         If InStr(mail.Subject, ws.Range("A1").Value) > 0 Then
            mail.Display 'if found display the email message
        End If
    Next

    Set wb = Nothing: Set ws = Nothing
    Set mail = Nothing: Set mailItems = Nothing
    Set mailFolder = Nothing: Set mailOL = Nothing
End Sub

正如您所说,Outlook 应该打开才能运行它。您可以将此宏设置为一个按钮,并在单元格 A1 中使用您的关键字(例如 PO 编号)在您的收件箱中进行搜索。您可以改进此代码以动态地为您服务。如果我理解正确,请告诉我。

【讨论】:

  • 谢谢。我明天回去工作时会试试这个。
  • 顺便说一下,如果您还没有添加Microsoft Outlook 15.0 Object Library(版本可能会更改),则需要从Tools -> References添加
  • 是的,当我编写一些 vba 以从 Excel 启动电子邮件时,该引用已启用。
【解决方案2】:

您需要启用 Outlook:// 协议。 Microsoft 现在仅在 Outlook 应用程序中提供对该协议的默认支持(请参阅https://support.microsoft.com/en-us/help/929590/known-issues-when-you-develop-custom-solutions-for-office-outlook-2007

但是,您可以为计算机中的其他应用手动执行此操作。您需要通过将以下条目添加到注册表来编辑 Windows 注册表:

[HKEY_CLASSES_ROOT\outlook]
"URL Protocol"=""
@="URL:Outlook Folders"

[HKEY_CLASSES_ROOT\outlook\DefaultIcon]
@="C:\\Program Files\\Microsoft Office\\Office15\\1033\\OUTLLIB.DLL,-9403"

[HKEY_CLASSES_ROOT\outlook\shell]
@="open"

[HKEY_CLASSES_ROOT\outlook\shell\open]
@=""

[HKEY_CLASSES_ROOT\outlook\shell\open\command]
@="\"C:\\Program Files\\Microsoft Office\\Office15\\OUTLOOK.EXE\" /select \"%1\""

您已完成此操作,您需要获取各个消息的消息 ID。

以下代码将获取消息ID

Sub GetOutlookMessageLinkID()
    'This procedue returns the outlook message ID for a the currenlty open outlook message.
    'Caveat: this message ID will be invalid if the message is moved to a differnt forldder.

    Dim myolApp
    Dim linkToMsg As String

    Set myolApp = CreateObject("Outlook.Application")
    linkToMsg = "Outlook:" & myolApp.ActiveInspector.CurrentItem.EntryID
    'linkToMsg now has the hyper link. you can use this as a clickable link to access the message
    'Enable the "Outlook:" protocol on your machine


End Sub

【讨论】:

  • 邮件一般被移动到确认文件夹中。所以位置的变化应该不是问题。不幸的是,这对我不起作用,因为我正在使用 Citrix 系统并且没有注册表访问权限。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多