Paste Text from clipboard unformatted

From The Document Foundation Wiki
Jump to: navigation, search


Here is a simple function, which allows you to paste unformatted text from the clipboard.

Just copy the function in a module, call the function from another procedure or function, for example:

sub clpboardTest
  MsgBox (getClipboardText)
end sub

Main function

Function getClipboardText () AS String

dim oClip as object ,oConverter as object
dim oClipContents as object ,oTypes as object
dim i%
oClip = createUnoService("")
oConverter = createUnoService("")
On Error Resume Next
oClipContents = oClip.getContents
oTypes = oClipContents.getTransferDataFlavors
For i=LBound(oTypes) To UBound(oTypes)
  If oTypes(i).MimeType = "text/plain;charset=utf-16" Then
    Exit For
  End If
If (i >= 0) Then
  On Error Resume Next
  getClipboardText = oConverter.convertToSimpleType _
End If
End Function