AW: Zwischenablage
15.03.2012 19:42:51
Nepumuk
Hallo,
so:
Option Explicit
Private Declare Function OpenClipboard Lib "user32.dll" ( _
ByVal hWnd As Long) As Long
Private Declare Function GetClipboardData Lib "user32.dll" ( _
ByVal wFormat As Long) As Long
Private Declare Function CloseClipboard Lib "user32.dll" () As Long
Private Declare Function IsClipboardFormatAvailable Lib "user32.dll" ( _
ByVal wFormat As Long) As Long
Private Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" ( _
ByVal lpString As Long) As Long
Private Declare Function GlobalLock Lib "kernel32.dll" ( _
ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32.dll" ( _
ByVal hMem As Long) As Long
Private Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA" ( _
ByVal lpString1 As Any, _
ByVal lpString2 As Any) As Long
Private Const CF_TEXT = 1
Public Sub Beispiel()
Dim strReturn As String
strReturn = StringFromClipboard
If strReturn <> "" Then
MsgBox CStr(UBound(Split(strReturn, vbCr)) + 1) & " Zeilen"
Else
MsgBox "Nix drin"
End If
End Sub
Private Function StringFromClipboard() As String
Dim lngHandle As Long, lngPointer As Long
Dim strText As String
If IsClipboardFormatAvailable(CF_TEXT) Then
Call OpenClipboard(0&)
lngHandle = GetClipboardData(CF_TEXT)
lngPointer = GlobalLock(lngHandle)
strText = Space$(lstrlen(ByVal lngPointer))
Call lstrcpy(strText, ByVal lngPointer)
Call GlobalUnlock(lngPointer)
Call CloseClipboard
StringFromClipboard = strText
End If
End Function
Gruß
Nepumuk