There’s a bit of a bug, if you want to call it that, in Windows 8 and Windows 10 that prevents the Microsoft Forms 2.0 Object Library solution from copying text to your clipboard. It has the added benefit of working for newer versions of Windows, as well. VBA is pretty good at converting your data types to strings before storing them in your clipboard, so you don’t have to worry about using the CStr function to manually convert.Īlthough I said this is the solution for Windows 7 and earlier, the following solution also works for Windows 7 and earlier. Sub CopyToClipboard2 () Dim clipboard As MSForms. The DataObject will be the bridge between your data and your clipboard. To copy to your clipboard in Windows 7 and earlier, you’ll need to first declare a variable as type MSForms.DataObject.
#Vba copying text clipboard how to#
Once your initial setup is complete, insert a module and continue reading to discover how to control your clipboard.