如何从电子邮件主题或身体中复制选定的文本,将其放入链接中并在浏览器中打开

发布于 2025-01-27 17:22:49 字数 2000 浏览 2 评论 0原文

我正在使用Office 365(桌面)的Outlook。

我正在尝试从电子邮件主题或身体中复制选定的文本,并将其放入预定义的网址中,然后在默认浏览器中打开它。

步骤:

  1. 打开或选择接收的消息
  2. 从主题或身体
  3. 运行宏的单词
  4. 默认浏览器应打开链接: https://www.dictionary.com/browse/delected word*

下面的代码仅在选定的单词在电子邮件的正文中时仅打开链接。

Sub OPEN_DICT()

Dim msg As Outlook.MailItem
Dim insp As Outlook.Inspector
Dim vURL1
Dim vURL2
Dim fullVID
Dim fullVURL

If Application.ActiveInspector Is Nothing Then
    If Application.ActiveExplorer.Selection.Count = 1 Then
        If Application.ActiveExplorer.Selection.Item(1).Class = olMail Then
            Set msg = Application.ActiveExplorer.Selection.Item(1)
        End If
    Else
        'to many items selected
        MsgBox "Please select one item"
    End If
Else
    Set insp = Application.ActiveInspector
    If insp.CurrentItem.Class = olMail Then
        Set msg = insp.CurrentItem
    End If
End If

If msg Is Nothing Then
    MsgBox "could not determine an item. Try again!"
Else
    If msg.GetInspector.EditorType = olEditorWord Then
        Set hed = msg.GetInspector.WordEditor
        Set appWord = hed.Application
        Set Rng = appWord.Selection
        With Rng
            .Copy
        End With

    End If
End If

If IsNumeric(Rng) Then
    fullVID = Rng
    vURL1 = "https://www.dictionary.com/browse/"
    vURL2 = fullVID
    fullVURL = vURL1 & vURL2

Else
    fullVID = Rng
    vURL1 = "https://www.dictionary.com/browse/"
    vURL2 = fullVID
    fullVURL = vURL1 & vURL2

End If

Dim build
Set build = CreateObject("Shell.Application")
build.ShellExecute "Chrome.exe", fullVURL, "", "", 1

ExitNewItem:
    Exit Sub

Set appWord = Nothing
Set insp = Nothing
Set Rng = Nothing
Set hed = Nothing
Set msg = Nothing

End Sub

如何在链接中打开电子邮件主题中所选的文本?
另外,它不应在Chrome中打开链接,而应在默认浏览器中打开。

I am using Outlook for Office 365 (desktop).

I am trying to copy selected text from the email subject or body, and put it into a predefined web address and open it in the default browser.

Steps:

  1. Open or select a received message
  2. Select a word from the subject or body
  3. Run the macro
  4. The default browser should open the link: https://www.dictionary.com/browse/*selected word*

The code below only opens the link when the selected word is in the body of the email.

Sub OPEN_DICT()

Dim msg As Outlook.MailItem
Dim insp As Outlook.Inspector
Dim vURL1
Dim vURL2
Dim fullVID
Dim fullVURL

If Application.ActiveInspector Is Nothing Then
    If Application.ActiveExplorer.Selection.Count = 1 Then
        If Application.ActiveExplorer.Selection.Item(1).Class = olMail Then
            Set msg = Application.ActiveExplorer.Selection.Item(1)
        End If
    Else
        'to many items selected
        MsgBox "Please select one item"
    End If
Else
    Set insp = Application.ActiveInspector
    If insp.CurrentItem.Class = olMail Then
        Set msg = insp.CurrentItem
    End If
End If

If msg Is Nothing Then
    MsgBox "could not determine an item. Try again!"
Else
    If msg.GetInspector.EditorType = olEditorWord Then
        Set hed = msg.GetInspector.WordEditor
        Set appWord = hed.Application
        Set Rng = appWord.Selection
        With Rng
            .Copy
        End With

    End If
End If

If IsNumeric(Rng) Then
    fullVID = Rng
    vURL1 = "https://www.dictionary.com/browse/"
    vURL2 = fullVID
    fullVURL = vURL1 & vURL2

Else
    fullVID = Rng
    vURL1 = "https://www.dictionary.com/browse/"
    vURL2 = fullVID
    fullVURL = vURL1 & vURL2

End If

Dim build
Set build = CreateObject("Shell.Application")
build.ShellExecute "Chrome.exe", fullVURL, "", "", 1

ExitNewItem:
    Exit Sub

Set appWord = Nothing
Set insp = Nothing
Set Rng = Nothing
Set hed = Nothing
Set msg = Nothing

End Sub

How can the selected text from the Subject of the email also be opened in the link?
Also, instead of opening the link in Chrome, it should open in the default browser.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

说谎友 2025-02-03 17:22:49

Outlook Object模型不会暴露任何可以让您从其任何控件中访问所选文本的任何内容,除了消息主体编辑器(以word.document.document对象)曝光。

最好的选择是使用低级Windows API(Findwindow等)找到主题编辑器或自动化或可访问性API。请参阅,例如,如何获得当前聚焦的文本?如何将任何应用程序选择的文本输入Windows表单应用程序

Outlook Object Model does not expose anything that would let you access selected (or any other) text from any of its controls except for the message body editor (which is exposed as Word.Document object).

Your best bet would be finding the Subject editor using low-level Windows API (FindWindow etc.) or Automation or Accessibility API to do that. See, for example, How to get selected text of currently focused window? or How to get selected text of any application into a windows form application

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文