How to write to the clipboard using VBA?

How to write to the clipboard using VBA?

T2ioTD
Enthusiast Enthusiast
984 Views
2 Replies
Message 1 of 3

How to write to the clipboard using VBA?

T2ioTD
Enthusiast
Enthusiast

I want to put a string in the clipboard, to ease the problematic writing to csv or Excel (for me it is a time consuming process, I prefer to send a string full of data via the clipboard, have Excel process it, and repeat this as many times as needed).

 

I have seen people using the DataObject, but Autocad is stating that this 'user-defined type not defined'.

I think I have to add a reference? But which one? Please help.

Dim myString As String: myString = "Hello, Clipboard"

Dim objectList As DataObject
objectList.SetText myString
objectList.PutInClipboard

 

0 Likes
Accepted solutions (1)
985 Views
2 Replies
Replies (2)
Message 2 of 3

seabrahenrique
Advocate
Advocate
Accepted solution

Hello!

 

I have been using this function:

 

Function FA_Clipboard(Optional StoreText As String) As String

'PURPOSE: Read/Write to Clipboard
'Source: ExcelHero.com (Daniel Ferry)

Dim X As Variant

'Store as variant for 64-bit VBA support
  X = StoreText

'Create HTMLFile Object
  With CreateObject("htmlfile")
    With .parentWindow.clipboardData
      Select Case True
        Case Len(StoreText)
          'Write to the clipboard
            .setData "text", X
        Case Else
          'Read from the clipboard (no variable passed through)
            Clipboard = .GetData("text")
      End Select
    End With
  End With
  
  ThisDrawing.Utility.Prompt "'" & StoreText & "' copiado para ára de transferência!" & vbCrLf

End Function

 

Hope can help u

Message 3 of 3

T2ioTD
Enthusiast
Enthusiast

Great, it works, but I had first to write:

Dim Clipboard

 

0 Likes