Access/VBA Library


Returns a String containing the content of the clipboard.


Return value

String : Content of the clipboard.

Function GetStringFromClipboard() As String
    Dim hCM As Long ' Handle clipboard memory
    Dim fpCM As Long ' Far pointer clipboard memory
    Dim strDummy As String
    If OpenClipboard(0&) Then
        hCM = GetClipboardData(CF_TEXT)
        If IsNull(hCM) Then Exit Function
        fpCM = GlobalLock(hCM)
        If Not IsNull(fpCM) Then
            strDummy = Space$(MAXSIZE)
            Call lstrcpy(strDummy, fpCM)
            Call GlobalUnlock(hCM)
            ' Remove null terminating character.
            strDummy = Mid(strDummy, 1, InStr(1, strDummy, Chr$(0), 0) - 1)
        End If
        Call CloseClipboard
    End If
    GetStringFromClipboard = strDummy
End Function

See also

  • GetClipboardData
  • GlobalAlloc
  • GlobalLock
  • GlobalUnlock
  • OpenClipboard
  • CloseClipboard