Save the clipboard history for reuse (2 Viewers)

xavier.batlle

Active member
Local time
Today, 01:05
Joined
Sep 1, 2023
Messages
249
This example shows how to save any text from the clipboard to a table so that it can be pasted later anywhere.

1773054642795.png
 

Attachments

Last edited:
This is a neat utility concept, and sometimes the simplest tools end up being the biggest time savers in real workflows. I remember making a "scratchpad" form in one of my personal databases years ago to keep track of temporary text snippets, so saving clipboard history feels like a practical extension of that. In my classes, I always tell students that little productivity tweaks like this can really add up, especially when you are working with data entry or repetitive tasks. Thanks for sharing a creative way to use Access for something a bit outside the usual box.
 
I like the Listener feature of your code. For simple pasting to and copying from the clipboard, I have been using a function from the spreadsheetguru using HTMLDocument instead of API calls. I use it as part of a BeforeUpdate event to save a corrected version of the text, allowing the user to paste it into the field.

Code:
' 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 TheClipboard(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 errTheClipboard
    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
doneTheClipboard:
    On Error Resume Next
    TheClipboard = ReturnValue
    Exit Function
errTheClipboard:
    ' LogError "TheClipboard"
    Resume doneTheClipboard
End Function
 

Users who are viewing this thread

  • Back
    Top Bottom