Outlook VBA - how to copy the currently selected text into clipboard? The Next CEO of Stack...

Bartok - Syncopation (1): Meaning of notes in between Grand Staff

Is it my responsibility to learn a new technology in my own time my employer wants to implement?

Why did CATV standarize in 75 ohms and everyone else in 50?

The exact meaning of 'Mom made me a sandwich'

Why isn't the Mueller report being released completely and unredacted?

How many extra stops do monopods offer for tele photographs?

Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?

Prepend last line of stdin to entire stdin

Domestic-to-international connection at Orlando (MCO)

Math-accent symbol over parentheses enclosing accented symbol (amsmath)

Newlines in BSD sed vs gsed

Powershell. How to parse gci Name?

Why didn't Khan get resurrected in the Genesis Explosion?

How to get from Geneva Airport to Metabief?

What steps are necessary to read a Modern SSD in Medieval Europe?

Where do students learn to solve polynomial equations these days?

Some questions about different axiomatic systems for neighbourhoods

Would a completely good Muggle be able to use a wand?

How to install OpenCV on Raspbian Stretch?

Solving system of ODEs with extra parameter

How a 64-bit process virtual address space is divided in Linux?

Does soap repel water?

Is wanting to ask what to write an indication that you need to change your story?

Why, when going from special to general relativity, do we just replace partial derivatives with covariant derivatives?



Outlook VBA - how to copy the currently selected text into clipboard?



The Next CEO of Stack OverflowOutlook 2007 attachments wont previewProblem printing from Outlook 2007How can I stop JavaScript from modifying the clipboard?Outlook - Prefix Reply With Character (HTML e-mails, too)How to copy Windows Explorer file selections and paste filenames as textHow to copy Skype text with timestamp and names in MacOSHow to copy partial selected/highlighted text within cell to clipboard, in excel vbaOutlook 2010 Macro to Convert Selected Email Messages to Plain TextAfter Outlook updated, the mail rules' Run Script option is missingpressing a button in an ie page using vba












4















My question



How can get the currently selected text in Microsoft Outlook 2007




  • in an open message window

  • or in the currently selected message in the preview pane


and copy it into the clipboard?



I am using Microsoft Outlook 2007.





What I already tried



I know that I can use DataObjects to put text into the clipboard or get text from the clipboard.



The difficulty is to get the currently selected text



I tried the following commands:




  • Outlook.copy

  • Outlook.selection.copy

  • Outlook.activeexplorer.selection.item(1). ...

    in many variations, but with no success.


I found some sources stating that it would not be possible to get the currently selected text in Outlook via VBA but I think it must at least be possible to invoke a Ctrl-C (copy) command and then use the content of the clipboard.



I also stumbled upon some solutions with the Inspector as described here, but I got an error message.
Maybe it is because I forgot to reference the "MS Word Object Library" - I'll try that on Monday.










share|improve this question




















  • 1





    What have you tried already? What were the results? Where are you getting stuck exactly?

    – Ƭᴇcʜιᴇ007
    Aug 1 '14 at 16:42








  • 1





    Thank you for your comment - sorry! I was really under pressure and in a hurry, but that's not the right and polite way to ask a question here. I've edited my question and would be thankful for removing the downvote. Thanks as well for your detailed reply - I'll try that out on Monday, when I have access to the computer again.

    – MostlyHarmless
    Aug 1 '14 at 19:01


















4















My question



How can get the currently selected text in Microsoft Outlook 2007




  • in an open message window

  • or in the currently selected message in the preview pane


and copy it into the clipboard?



I am using Microsoft Outlook 2007.





What I already tried



I know that I can use DataObjects to put text into the clipboard or get text from the clipboard.



The difficulty is to get the currently selected text



I tried the following commands:




  • Outlook.copy

  • Outlook.selection.copy

  • Outlook.activeexplorer.selection.item(1). ...

    in many variations, but with no success.


I found some sources stating that it would not be possible to get the currently selected text in Outlook via VBA but I think it must at least be possible to invoke a Ctrl-C (copy) command and then use the content of the clipboard.



I also stumbled upon some solutions with the Inspector as described here, but I got an error message.
Maybe it is because I forgot to reference the "MS Word Object Library" - I'll try that on Monday.










share|improve this question




















  • 1





    What have you tried already? What were the results? Where are you getting stuck exactly?

    – Ƭᴇcʜιᴇ007
    Aug 1 '14 at 16:42








  • 1





    Thank you for your comment - sorry! I was really under pressure and in a hurry, but that's not the right and polite way to ask a question here. I've edited my question and would be thankful for removing the downvote. Thanks as well for your detailed reply - I'll try that out on Monday, when I have access to the computer again.

    – MostlyHarmless
    Aug 1 '14 at 19:01
















4












4








4


1






My question



How can get the currently selected text in Microsoft Outlook 2007




  • in an open message window

  • or in the currently selected message in the preview pane


and copy it into the clipboard?



I am using Microsoft Outlook 2007.





What I already tried



I know that I can use DataObjects to put text into the clipboard or get text from the clipboard.



The difficulty is to get the currently selected text



I tried the following commands:




  • Outlook.copy

  • Outlook.selection.copy

  • Outlook.activeexplorer.selection.item(1). ...

    in many variations, but with no success.


I found some sources stating that it would not be possible to get the currently selected text in Outlook via VBA but I think it must at least be possible to invoke a Ctrl-C (copy) command and then use the content of the clipboard.



I also stumbled upon some solutions with the Inspector as described here, but I got an error message.
Maybe it is because I forgot to reference the "MS Word Object Library" - I'll try that on Monday.










share|improve this question
















My question



How can get the currently selected text in Microsoft Outlook 2007




  • in an open message window

  • or in the currently selected message in the preview pane


and copy it into the clipboard?



I am using Microsoft Outlook 2007.





What I already tried



I know that I can use DataObjects to put text into the clipboard or get text from the clipboard.



The difficulty is to get the currently selected text



I tried the following commands:




  • Outlook.copy

  • Outlook.selection.copy

  • Outlook.activeexplorer.selection.item(1). ...

    in many variations, but with no success.


I found some sources stating that it would not be possible to get the currently selected text in Outlook via VBA but I think it must at least be possible to invoke a Ctrl-C (copy) command and then use the content of the clipboard.



I also stumbled upon some solutions with the Inspector as described here, but I got an error message.
Maybe it is because I forgot to reference the "MS Word Object Library" - I'll try that on Monday.







microsoft-outlook-2007 vba clipboard






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 20 '17 at 10:17









Community

1




1










asked Aug 1 '14 at 13:44









MostlyHarmlessMostlyHarmless

98852143




98852143








  • 1





    What have you tried already? What were the results? Where are you getting stuck exactly?

    – Ƭᴇcʜιᴇ007
    Aug 1 '14 at 16:42








  • 1





    Thank you for your comment - sorry! I was really under pressure and in a hurry, but that's not the right and polite way to ask a question here. I've edited my question and would be thankful for removing the downvote. Thanks as well for your detailed reply - I'll try that out on Monday, when I have access to the computer again.

    – MostlyHarmless
    Aug 1 '14 at 19:01
















  • 1





    What have you tried already? What were the results? Where are you getting stuck exactly?

    – Ƭᴇcʜιᴇ007
    Aug 1 '14 at 16:42








  • 1





    Thank you for your comment - sorry! I was really under pressure and in a hurry, but that's not the right and polite way to ask a question here. I've edited my question and would be thankful for removing the downvote. Thanks as well for your detailed reply - I'll try that out on Monday, when I have access to the computer again.

    – MostlyHarmless
    Aug 1 '14 at 19:01










1




1





What have you tried already? What were the results? Where are you getting stuck exactly?

– Ƭᴇcʜιᴇ007
Aug 1 '14 at 16:42







What have you tried already? What were the results? Where are you getting stuck exactly?

– Ƭᴇcʜιᴇ007
Aug 1 '14 at 16:42






1




1





Thank you for your comment - sorry! I was really under pressure and in a hurry, but that's not the right and polite way to ask a question here. I've edited my question and would be thankful for removing the downvote. Thanks as well for your detailed reply - I'll try that out on Monday, when I have access to the computer again.

– MostlyHarmless
Aug 1 '14 at 19:01







Thank you for your comment - sorry! I was really under pressure and in a hurry, but that's not the right and polite way to ask a question here. I've edited my question and would be thankful for removing the downvote. Thanks as well for your detailed reply - I'll try that out on Monday, when I have access to the computer again.

– MostlyHarmless
Aug 1 '14 at 19:01












2 Answers
2






active

oldest

votes


















5














Since Outlook uses Word (if installed) as its editor, it's a bit of a pain to get to get it. :)



You have to reference the Word application, then the Word document, then the selection.



For the following code to work in Outlook you need to add a Reference (VBA Editor -> Tools -> References) to the "Microsoft Word Object Library", and one to the "Microsoft Forms Object Library", so that we can actually copy the text the system clipboard.



Note: For me, in Office 2013, the MS Forms object wasn't in the list, so I just added a UserForm to the VBA project, which added the reference automatically, and then just deleted the form. The reference stuck.



Anyhow I dug around many sources and here's some code I stuck together that will copy the highlighted text to the clipboard, with some basic error checking (tested in Outlook 2013):



Public Sub CopyTextToClipBoard()

Dim objItem As Object
Dim objInsp As Outlook.Inspector

Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim objSel As Word.Selection
On Error Resume Next

' Reference the current Outlook item
Set objItem = Application.ActiveInspector.CurrentItem
If Not objItem Is Nothing Then
If objItem.Class = olMail Then
Set objInsp = objItem.GetInspector
If objInsp.EditorType = olEditorWord Then
Set objDoc = objInsp.WordEditor
Set objWord = objDoc.Application
Set objSel = objWord.Selection

On Error GoTo NotText
With New MSForms.DataObject
.SetText objSel.Text
.PutInClipboard
End With
On Error Resume Next

End If
End If
End If

Set objItem = Nothing
Set objWord = Nothing
Set objSel = Nothing
Set objInsp = Nothing

NotText:
If Err <> 0 Then
MsgBox "Data on clipboard is not text."
End If

End Sub





share|improve this answer





















  • 1





    thanks, it works fine - even if the text is selected in the preview pane (Outlook 2007)! (Sorry for my late feedback)

    – MostlyHarmless
    Apr 17 '15 at 15:59



















0














if a use the code provided, I get only 1 selected text of my email.



how can i edit this code, in order to get more than one text selected?



Of course the 2 text selected are in the same active mail.



Thanks.






share|improve this answer








New contributor




Luciano Fattore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f791151%2foutlook-vba-how-to-copy-the-currently-selected-text-into-clipboard%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5














    Since Outlook uses Word (if installed) as its editor, it's a bit of a pain to get to get it. :)



    You have to reference the Word application, then the Word document, then the selection.



    For the following code to work in Outlook you need to add a Reference (VBA Editor -> Tools -> References) to the "Microsoft Word Object Library", and one to the "Microsoft Forms Object Library", so that we can actually copy the text the system clipboard.



    Note: For me, in Office 2013, the MS Forms object wasn't in the list, so I just added a UserForm to the VBA project, which added the reference automatically, and then just deleted the form. The reference stuck.



    Anyhow I dug around many sources and here's some code I stuck together that will copy the highlighted text to the clipboard, with some basic error checking (tested in Outlook 2013):



    Public Sub CopyTextToClipBoard()

    Dim objItem As Object
    Dim objInsp As Outlook.Inspector

    Dim objWord As Word.Application
    Dim objDoc As Word.Document
    Dim objSel As Word.Selection
    On Error Resume Next

    ' Reference the current Outlook item
    Set objItem = Application.ActiveInspector.CurrentItem
    If Not objItem Is Nothing Then
    If objItem.Class = olMail Then
    Set objInsp = objItem.GetInspector
    If objInsp.EditorType = olEditorWord Then
    Set objDoc = objInsp.WordEditor
    Set objWord = objDoc.Application
    Set objSel = objWord.Selection

    On Error GoTo NotText
    With New MSForms.DataObject
    .SetText objSel.Text
    .PutInClipboard
    End With
    On Error Resume Next

    End If
    End If
    End If

    Set objItem = Nothing
    Set objWord = Nothing
    Set objSel = Nothing
    Set objInsp = Nothing

    NotText:
    If Err <> 0 Then
    MsgBox "Data on clipboard is not text."
    End If

    End Sub





    share|improve this answer





















    • 1





      thanks, it works fine - even if the text is selected in the preview pane (Outlook 2007)! (Sorry for my late feedback)

      – MostlyHarmless
      Apr 17 '15 at 15:59
















    5














    Since Outlook uses Word (if installed) as its editor, it's a bit of a pain to get to get it. :)



    You have to reference the Word application, then the Word document, then the selection.



    For the following code to work in Outlook you need to add a Reference (VBA Editor -> Tools -> References) to the "Microsoft Word Object Library", and one to the "Microsoft Forms Object Library", so that we can actually copy the text the system clipboard.



    Note: For me, in Office 2013, the MS Forms object wasn't in the list, so I just added a UserForm to the VBA project, which added the reference automatically, and then just deleted the form. The reference stuck.



    Anyhow I dug around many sources and here's some code I stuck together that will copy the highlighted text to the clipboard, with some basic error checking (tested in Outlook 2013):



    Public Sub CopyTextToClipBoard()

    Dim objItem As Object
    Dim objInsp As Outlook.Inspector

    Dim objWord As Word.Application
    Dim objDoc As Word.Document
    Dim objSel As Word.Selection
    On Error Resume Next

    ' Reference the current Outlook item
    Set objItem = Application.ActiveInspector.CurrentItem
    If Not objItem Is Nothing Then
    If objItem.Class = olMail Then
    Set objInsp = objItem.GetInspector
    If objInsp.EditorType = olEditorWord Then
    Set objDoc = objInsp.WordEditor
    Set objWord = objDoc.Application
    Set objSel = objWord.Selection

    On Error GoTo NotText
    With New MSForms.DataObject
    .SetText objSel.Text
    .PutInClipboard
    End With
    On Error Resume Next

    End If
    End If
    End If

    Set objItem = Nothing
    Set objWord = Nothing
    Set objSel = Nothing
    Set objInsp = Nothing

    NotText:
    If Err <> 0 Then
    MsgBox "Data on clipboard is not text."
    End If

    End Sub





    share|improve this answer





















    • 1





      thanks, it works fine - even if the text is selected in the preview pane (Outlook 2007)! (Sorry for my late feedback)

      – MostlyHarmless
      Apr 17 '15 at 15:59














    5












    5








    5







    Since Outlook uses Word (if installed) as its editor, it's a bit of a pain to get to get it. :)



    You have to reference the Word application, then the Word document, then the selection.



    For the following code to work in Outlook you need to add a Reference (VBA Editor -> Tools -> References) to the "Microsoft Word Object Library", and one to the "Microsoft Forms Object Library", so that we can actually copy the text the system clipboard.



    Note: For me, in Office 2013, the MS Forms object wasn't in the list, so I just added a UserForm to the VBA project, which added the reference automatically, and then just deleted the form. The reference stuck.



    Anyhow I dug around many sources and here's some code I stuck together that will copy the highlighted text to the clipboard, with some basic error checking (tested in Outlook 2013):



    Public Sub CopyTextToClipBoard()

    Dim objItem As Object
    Dim objInsp As Outlook.Inspector

    Dim objWord As Word.Application
    Dim objDoc As Word.Document
    Dim objSel As Word.Selection
    On Error Resume Next

    ' Reference the current Outlook item
    Set objItem = Application.ActiveInspector.CurrentItem
    If Not objItem Is Nothing Then
    If objItem.Class = olMail Then
    Set objInsp = objItem.GetInspector
    If objInsp.EditorType = olEditorWord Then
    Set objDoc = objInsp.WordEditor
    Set objWord = objDoc.Application
    Set objSel = objWord.Selection

    On Error GoTo NotText
    With New MSForms.DataObject
    .SetText objSel.Text
    .PutInClipboard
    End With
    On Error Resume Next

    End If
    End If
    End If

    Set objItem = Nothing
    Set objWord = Nothing
    Set objSel = Nothing
    Set objInsp = Nothing

    NotText:
    If Err <> 0 Then
    MsgBox "Data on clipboard is not text."
    End If

    End Sub





    share|improve this answer















    Since Outlook uses Word (if installed) as its editor, it's a bit of a pain to get to get it. :)



    You have to reference the Word application, then the Word document, then the selection.



    For the following code to work in Outlook you need to add a Reference (VBA Editor -> Tools -> References) to the "Microsoft Word Object Library", and one to the "Microsoft Forms Object Library", so that we can actually copy the text the system clipboard.



    Note: For me, in Office 2013, the MS Forms object wasn't in the list, so I just added a UserForm to the VBA project, which added the reference automatically, and then just deleted the form. The reference stuck.



    Anyhow I dug around many sources and here's some code I stuck together that will copy the highlighted text to the clipboard, with some basic error checking (tested in Outlook 2013):



    Public Sub CopyTextToClipBoard()

    Dim objItem As Object
    Dim objInsp As Outlook.Inspector

    Dim objWord As Word.Application
    Dim objDoc As Word.Document
    Dim objSel As Word.Selection
    On Error Resume Next

    ' Reference the current Outlook item
    Set objItem = Application.ActiveInspector.CurrentItem
    If Not objItem Is Nothing Then
    If objItem.Class = olMail Then
    Set objInsp = objItem.GetInspector
    If objInsp.EditorType = olEditorWord Then
    Set objDoc = objInsp.WordEditor
    Set objWord = objDoc.Application
    Set objSel = objWord.Selection

    On Error GoTo NotText
    With New MSForms.DataObject
    .SetText objSel.Text
    .PutInClipboard
    End With
    On Error Resume Next

    End If
    End If
    End If

    Set objItem = Nothing
    Set objWord = Nothing
    Set objSel = Nothing
    Set objInsp = Nothing

    NotText:
    If Err <> 0 Then
    MsgBox "Data on clipboard is not text."
    End If

    End Sub






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Aug 1 '14 at 18:55

























    answered Aug 1 '14 at 16:46









    Ƭᴇcʜιᴇ007Ƭᴇcʜιᴇ007

    99.9k14158221




    99.9k14158221








    • 1





      thanks, it works fine - even if the text is selected in the preview pane (Outlook 2007)! (Sorry for my late feedback)

      – MostlyHarmless
      Apr 17 '15 at 15:59














    • 1





      thanks, it works fine - even if the text is selected in the preview pane (Outlook 2007)! (Sorry for my late feedback)

      – MostlyHarmless
      Apr 17 '15 at 15:59








    1




    1





    thanks, it works fine - even if the text is selected in the preview pane (Outlook 2007)! (Sorry for my late feedback)

    – MostlyHarmless
    Apr 17 '15 at 15:59





    thanks, it works fine - even if the text is selected in the preview pane (Outlook 2007)! (Sorry for my late feedback)

    – MostlyHarmless
    Apr 17 '15 at 15:59













    0














    if a use the code provided, I get only 1 selected text of my email.



    how can i edit this code, in order to get more than one text selected?



    Of course the 2 text selected are in the same active mail.



    Thanks.






    share|improve this answer








    New contributor




    Luciano Fattore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.

























      0














      if a use the code provided, I get only 1 selected text of my email.



      how can i edit this code, in order to get more than one text selected?



      Of course the 2 text selected are in the same active mail.



      Thanks.






      share|improve this answer








      New contributor




      Luciano Fattore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.























        0












        0








        0







        if a use the code provided, I get only 1 selected text of my email.



        how can i edit this code, in order to get more than one text selected?



        Of course the 2 text selected are in the same active mail.



        Thanks.






        share|improve this answer








        New contributor




        Luciano Fattore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.










        if a use the code provided, I get only 1 selected text of my email.



        how can i edit this code, in order to get more than one text selected?



        Of course the 2 text selected are in the same active mail.



        Thanks.







        share|improve this answer








        New contributor




        Luciano Fattore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        share|improve this answer



        share|improve this answer






        New contributor




        Luciano Fattore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered 23 mins ago









        Luciano FattoreLuciano Fattore

        1




        1




        New contributor




        Luciano Fattore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        Luciano Fattore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        Luciano Fattore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f791151%2foutlook-vba-how-to-copy-the-currently-selected-text-into-clipboard%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Cannot install PyQt5 The Next CEO of Stack OverflowCannot install tcpreplay 3.4.4cannot...

            Kapp-Putsch Acontecimentos | Outros artigos | Menu de navegação

            Why did early computer designers eschew integers? The Next CEO of Stack OverflowWhat register...