Vielen Dank
aus dem Link von Volti habe ich "Function GlobalSize" gelernt um die Anzahl der Zeichen im Clipboard zu bestimmen. Der erste Test war ganz gut, aber es bedarf noch mehr Prüfungen.
In meinem Archiv habe ich diesen Code gefunden:
Code:
Sub ListClipFormats()
Dim Arr, Fmt
Arr = Application.ClipboardFormats
For Each Fmt In Application.ClipboardFormats
Select Case Fmt
Case xlClipboardFormatBIFF Or 8: Debug.Print "Binary Interchange file format for Excel version 2.x"
Case xlClipboardFormatBIFF12 Or 63: Debug.Print "Binary Interchange file format 12"
Case xlClipboardFormatBIFF2 Or 18: Debug.Print "Binary Interchange file format 2"
Case xlClipboardFormatBIFF3 Or 20: Debug.Print "Binary Interchange file format 3"
Case xlClipboardFormatBIFF4 Or 30: Debug.Print "Binary Interchange file format 4"
Case xlClipboardFormatBinary Or 15: Debug.Print "Binary format"
Case xlClipboardFormatBitmap Or 9: Debug.Print "Bitmap format"
Case xlClipboardFormatCGM Or 13: Debug.Print "CGM format"
Case xlClipboardFormatCSV Or 5: Debug.Print "CSV format"
Case xlClipboardFormatDIF Or 4: Debug.Print "DIF format"
Case xlClipboardFormatDspText Or 12: Debug.Print "Dsp Text format"
Case xlClipboardFormatEmbeddedObject Or 21: Debug.Print "Embedded Object"
Case xlClipboardFormatEmbedSource Or 22: Debug.Print "Embedded Source"
Case xlClipboardFormatLink Or 11: Debug.Print "Link"
Case xlClipboardFormatLinkSource Or 23: Debug.Print "Link to the source file"
Case xlClipboardFormatLinkSourceDesc Or 32: Debug.Print "Link to the source description"
Case xlClipboardFormatMovie Or 24: Debug.Print "Movie"
Case xlClipboardFormatNative Or 14: Debug.Print "Native"
Case xlClipboardFormatObjectDesc Or 31: Debug.Print "Object description"
Case xlClipboardFormatObjectLink Or 19: Debug.Print "Object link"
Case xlClipboardFormatOwnerLink Or 17: Debug.Print "Link to the owner"
Case xlClipboardFormatPICT Or 2: Debug.Print "Picture"
Case xlClipboardFormatPrintPICT Or 3: Debug.Print "Print picture"
Case xlClipboardFormatRTF Or 7: Debug.Print "RTF format"
Case xlClipboardFormatScreenPICT Or 29: Debug.Print "Screen Picture"
Case xlClipboardFormatStandardFont Or 28: Debug.Print "Standard Font"
Case xlClipboardFormatStandardScale Or 27: Debug.Print "Standard Scale"
Case xlClipboardFormatSYLK Or 6: Debug.Print "; SYLK"
Case xlClipboardFormatTable Or 16: Debug.Print "; Table"
Case xlClipboardFormatText Or 0: Debug.Print "Text"
Case xlClipboardFormatToolFace Or 25: Debug.Print "Tool Face"
Case xlClipboardFormatToolFacePICT Or 26: Debug.Print "Tool Face Picture"
Case xlClipboardFormatVALU Or 1: Debug.Print "Value"
Case xlClipboardFormatWK1 Or 10: Debug.Print "Workbook"
End Select
Next Fmt
End Sub
Nach dem Kopieren eines Excel-Range mit Texten war das Ergebnis:
Text
Picture
DIF format
CSV format
; SYLK
RTF format
Binary Interchange file format for Excel version 2.x
Bitmap format
Link
Dsp Text format
Native
Link to the owner
Object link
Embedded Source
Link to the source file
Object description
Link to the source description
Binary Interchange file format 12
Das konnte ich nicht interpretieren. Erwartet hatte ich entweder "Table", "Text", "Object" oder "Link".
Wenn die Anzahl der Zeichen im Clipboard valide wäre, könnte ich das zur Kontrolle nutzen.
mfg
Dieser Code scheint die Anzahl der Zeichen im Clipboard zu bestimmen, ohne Änderungen vorzunehmen:
Code:
Option Explicit
Private Declare PtrSafe Function GlobalSize Lib "kernel32" ( _
ByVal hMem As LongPtr) As LongPtr
Private Declare PtrSafe Function IsClipboardFormatAvailable Lib "user32" ( _
ByVal wFormat As Long) As Long
Private Declare PtrSafe Function GetClipboardData Lib "user32" ( _
ByVal wFormat As Long) As LongPtr
Private Declare PtrSafe Function OpenClipboard Lib "user32" ( _
ByVal hWnd As LongPtr) As Long
Private Declare PtrSafe Function CloseClipboard Lib "user32" () As Long
Sub T_Clip_Size()
Dim hMem As LongPtr, lpGMem As LongPtr, sCliptext As String, i As Long
Const CF_TEXT As Long = 1
If IsClipboardFormatAvailable(CF_TEXT) > 0 Then ' Daten vorhanden?
OpenClipboard 0& ' Zwischenablage öffnen
hMem = GetClipboardData(CF_TEXT) ' TEXT aus Zwischenablage
If hMem > 0 Then
Debug.Print CLng(GlobalSize(hMem))
End If
CloseClipboard ' Zwischenablage schließen
End If
End Sub
Da mein Code viele tausend Zeichen kopiert, sollte andere copies von einem User unterschieden werden. Mal sehen was ein echter Test bringt.
mfg