Macro or vba to insert email clipboard text into an excel note (1 Viewer)

Sam Summers

Registered User.
Local time
Today, 08:08
Joined
Sep 17, 2001
Messages
940
Hi there,
I have played about with this and searched and searched but not much closer.
It should be possible but maybe it isn't?

Basically after copying text from an email in outlook (clipboard i guess).
I want to create a macro or procedure to create a note and insert the clipboard text in one command or shortcut.

Many thanks in advance
 
I use a function from ExcelHero.com

In your form after copying from whatever.

me.YourTextBox = pai1_ClipBoard()

Code:
'----------------------
' Replacing API code in modzClipBoard 10-10-22
' Copy ClipboardText if not empty to clipboard and return vbnullstring
' Return clipboard text if ClipboardText is empty
' Early bind using ref to Microsoft HTML Object Library
'
Public Function pai1_Clipboard(Optional ByVal ClipboardText As String = vbNullString) As String
    'PURPOSE: Read/Write to Clipboard
    'Source: ExcelHero.com (Daniel Ferry)
    'https://www.thespreadsheetguru.com/blog/2015/1/13/how-to-use-vba-code-to-copy-text-to-the-clipboard
    On Error GoTo errpai1_Clipboard
    Dim ReturnValue As String
    Dim X As Variant 'Store as variant for 64-bit VBA support

    X = ClipboardText
'    With New HTMLDocument ' Early binding
      With CreateObject("htmlfile")
        With .parentWindow.clipboardData
          Select Case True
            Case Len(ClipboardText)
                'Write to the clipboard
                .SetData "text", X
            Case Else
                'Read from the clipboard (no variable passed through)
                ReturnValue = .GetData("text")
          End Select
        End With
      End With
donepai1_Clipboard:
    On Error Resume Next
    pai1_Clipboard = ReturnValue
    Exit Function
errpai1_Clipboard:
    LogError "pai1_Clipboard"
    Resume donepai1_Clipboard
End Function
 
YES - there are several ways to access the clipboard, I've actually had best luck with the internet based one that ron suggested 💪🤞
 
I would use the recorder to get the bulk of the code, then use/find paste from clipboard code.
 
> clipboard i guess
That is one way, but another elegant way is to use COM Automation with Outlook. Note that ONLY works with what's now called Classic Outlook, not with New Outlook (which does not support COM Automation at all).
If you want to go down this road, I would use these search terms: vba com automation with outlook copy email text
 
Tom makes a good point, although I assumed that the portion being copied was just a small portion of the email body, not the whole thing, at the user's discretion.
But I like where he is going with this. I once made a script to go through outlook emails and parse the text and figure out little bits that I wanted from it - it's not impossible, but might seem pretty challenging depending on where you're at
 

Users who are viewing this thread

  • Back
    Top Bottom