

If you just want to retrieve text (CF_TEXT) from the clipboard, a single line of code is enough. This means you do not need to explicitly create an instance of that class but can just reference this class as Clipboard in your code. The following function can be called to retrieve the current clipboard content/string. So it is pure and simple VBA code that should work in any VBA application regardless of bitness. The class module Clipboard hat its Attribute VB_PredeclaredId set to True. This approach does not require any APIs, nor does it require any VBA References to be set as it uses Late Binding techniques. Then open the VBA-Editor with your application, Use the “File” -> “Import File” menu to import the Clipboard.cls file into your application. When I put the code it puts it in the clipboard. Each line is dropped using alt-enter when entering the text into the cell. To integrate this class into your application, download the Clipboard-ZIP-Archive and unpack it. Thanks for that but it still doesnt do it. It is a VBA class module that can be used in any VBA enabled application. This download not limited to Microsoft Access. I guess, I will add that whenever I find the time. – It cannot write any data to the clipboard yet. It can retrieve plain text from the clipboard, ANSI and Unicode (untested!), and the file content of any file on the clipboard (tested only with text). Capabilitiesĭue to time constraints, this sample is current very limited only. Nevertheless, I managed to create a basic VBA Clipboard class that nicely wraps this complexity under its hood.

The Windows Clipboard API proved to be way more complex than I originally anticipated. Despite being busy otherwise I couldn’t resist to hack a small sample class together, which would retrieve the file content of a file from the clipboard using the GetClipboardData function from the Windows API. However, none of those samples work when you don’t have the text directly in the clipboard but rather a file containing text. Well, there are couple of samples available to get Text from the clipboard using the Windows API.

I recently encountered a question on a forum where someone copied a text file from his email inbox onto the clipboard and needed to retrieve this file or its content in Access VBA. By Philipp Stiefel, originally published September 3rd, 2019, last updated September 3rd, 2019
