Macro pour coller du texte non formaté du presse-papiers

From The Document Foundation Wiki
Jump to navigation Jump to search
This page is a translated version of the page Macros/General/008 and the translation is 100% complete.
Other languages:
English • ‎español • ‎français • ‎italiano


Cette macro vous permet de coller du texte non formaté à partir du presse-papiers.


En LibreOffice Basic:

Option Explicit

Sub ClipboardTest
    MsgBox getClipboardText
End Sub ' ClipboardTest

Function getClipboardText() As String
    '''Renvoie une "String" du texte du presse-papiers courant'''

    Dim oClip As Object '
    Dim oConverter As Object '
    Dim oClipContents As Object
    Dim 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 ' getClipboardText

Fichier ODT pour tester la macro