Link to home
Create AccountLog in
Outlook

Outlook

--

Questions

--

Followers

Top Experts

Avatar of nummagumma2
nummagumma2🇺🇸

outlook script to copy email to clipboard
I have some handy scripts to convert htm to txt, delete attachments from multiple emails, save attachments from multiple... but can't find anything that will take the currently highlighted email and copy it to the clipboard.

I need it to contain the FROM/TO /Date information.

Currently my manual way to do this is to REPLY to the email, select the part I want, and CTRL-C.

There's gotta be code that will get all this.

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of David LeeDavid Lee🇺🇸

Hi, nummagumma2.

What version of Outlook?

Avatar of nummagumma2nummagumma2🇺🇸

ASKER

Oh wow, sorry BlueDevilFan - I didn't notice any email that someone had replied.

Outlook 2003 and 2007.

Avatar of David LeeDavid Lee🇺🇸

No problem.  How do you want the information formatted?

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of nummagumma2nummagumma2🇺🇸

ASKER

Currently I'm just copying the contents of the text that appears when you click REPLY.  The components I want to capture are FROM, SENT, SUBJECT and the body.


Avatar of David LeeDavid Lee🇺🇸

I understood which fields you wanted.  How do you want them formatted?  In other words, when you paste the data into into a message how do you want it to look?

Avatar of nummagumma2nummagumma2🇺🇸

ASKER

Oops, sorry.   I'm pasting into a plain-text format.  The format it looks when you copy from a "reply" is fine.  I guess this is pulling out with VB so:

From:
Sent:
To:
Subj:

<body>

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of nummagumma2nummagumma2🇺🇸

ASKER

In thinking about the manual process I do right now, I think it would be great if there was a second version of this code that would capture all the <body> until another "FROM: xxx" is found in the thread; but that's asking for a lot I think.

ASKER CERTIFIED SOLUTION
Avatar of David LeeDavid Lee🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of nummagumma2nummagumma2🇺🇸

ASKER

Awesome.  Works exactly as expected.   If you can do the second, shall I create another question?

Avatar of David LeeDavid Lee🇺🇸

Cool.  For the second one you want to copy everything from the beginning of the message down to the first From, is that right?

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of nummagumma2nummagumma2🇺🇸

ASKER

Exactly correct.

Avatar of David LeeDavid Lee🇺🇸

This version copies the body down to the first "From:".
Sub CopyMsg2Clipboard()
    Dim olkMsg As Object, strData As String, intStart As Integer
    Select Case TypeName(Outlook.ActiveWindow)
        Case "Explorer"
            Set olkMsg = Outlook.Application.ActiveExplorer.Selection(1)
        Case "Inspector"
            Set olkMsg = Outlook.ActiveInspector.CurrentItem
    End Select
    If TypeName(olkMsg) = "Nothing" Then
        MsgBox "This macro only works with emails.", vbExclamation + vbOKOnly, "Copy Message to Clipboard"
    Else
        intStart = InStr(1, olkMsg.Body, "From:") - 1
        strData = "From: " & olkMsg.SenderName & vbCrLf _
            & "Sent: " & olkMsg.SentOn & vbCrLf _
            & "To: " & olkMsg.To & vbCrLf _
            & "Subj: " & olkMsg.Subject & vbCrLf & vbCrLf _
            & Mid(olkMsg.Body, 1, intStart)
        ClipBoard_SetData strData
    End If
    Set olkMsg = Nothing
End Sub

Open in new window


Avatar of nummagumma2nummagumma2🇺🇸

ASKER

Brilliant!  How do I give you more points?!

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of David LeeDavid Lee🇺🇸

Thanks, but not necessary.  It was a simple change to the original script.
Outlook

Outlook

--

Questions

--

Followers

Top Experts

Microsoft Outlook is a personal information manager from Microsoft, available as a part of the Microsoft Office suite. Although often used mainly as an email application, it also includes a calendar, task manager, contact manager, note-taker, journal, and web browser.