Get text from clipboard using GetText – avoid error on empty clipboard

Handle the errors with On Error GoTo as shown here: Sub GetClipBoardText() Dim DataObj As MSForms.DataObject Set DataObj = New MsForms.DataObject ‘<~~ Amended as per jp’s suggestion On Error GoTo Whoa ‘~~> Get data from the clipboard. DataObj.GetFromClipboard ‘~~> Get clipboard contents myString = DataObj.GetText(1) MsgBox myString Exit Sub Whoa: If Err <> 0 Then … Read more

event.clipboardData.setData in copy event

Clipboard APIs were indeed in active development as of 2016, but things have stabilized since then: Using event.clipboardData.setData() is supported Changing the clipboard with event.clipboardData.setData() inside a ‘copy’ event handler is allowed by the spec (as long as the event is not synthetic). Note that you need to prevent the default action in the event … Read more