HERBERS
Excel-Forum
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Entdecke rund 2 Millionen Excel-Lösungen im
Forumsarchiv
Forumbeitrag
Excel-Version des Fragestellers:
365 Business
Erfahrungslevel des Fragestellers:
Excel gut - VBA bescheiden
Alwin Weisangler
26.05.2026 14:25:25
AW: Problem mit 2-spaltiger Listbox
eine Beispiellösung per API:


Option Explicit

#If VBA7 Then
Private Declare PtrSafe Function OpenClipboard Lib "user32.dll" (ByVal hwnd As LongPtr) As Long
Private Declare PtrSafe Function CloseClipboard Lib "user32" () As Long
Private Declare PtrSafe Function EmptyClipboard Lib "user32" () As Long
Private Declare PtrSafe Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As LongPtr) As LongPtr
Private Declare PtrSafe Function GlobalAlloc Lib "kernel32.dll" (ByVal wFlags As Long, ByVal dwBytes As LongPtr) As LongPtr
Private Declare PtrSafe Function GlobalLock Lib "kernel32.dll" (ByVal hMem As LongPtr) As LongPtr
Private Declare PtrSafe Function GlobalUnlock Lib "kernel32.dll" (ByVal hMem As LongPtr) As Long
Private Declare PtrSafe Function objGlobSpeicher Lib "kernel32.dll" Alias "GlobalFree" (ByVal hMem As LongPtr) As LongPtr
Private Declare PtrSafe Function strCopy Lib "kernel32.dll" Alias "lstrcpy" (ByVal lpStr1 As Any, ByVal lpStr2 As Any) As Long
Private Kennung As LongPtr
#Else
Private Declare Function OpenClipboard Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function EmptyClipboard Lib "user32" () As Long
Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Private Declare Function GlobalAlloc Lib "kernel32.dll" (ByVal wFlags As Long, ByVal dwBytes 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 objGlobSpeicher Lib "kernel32.dll" Alias "GlobalFree" (ByVal hMem As Long) As Long
Private Declare Function strCopy Lib "kernel32.dll" Alias "lstrcpy" (ByVal lpStr1 As Any, ByVal lpStr2 As Any) As Long
Private Kennung As Long
#End If

Private Sub StringInClipboard(strText As String)
Kennung = GlobalAlloc(2, Len(strText) + 1)
strCopy GlobalLock(Kennung), strText
GlobalUnlock Kennung
OpenClipboard 0&
EmptyClipboard
SetClipboardData 1&, Kennung
CloseClipboard
objGlobSpeicher Kennung
End Sub

Public Sub Einlesen()
Dim rngWerte$, i&
For i = 1 To 4
rngWerte = rngWerte & Tabelle1.Cells(i, 6) & vbCrLf
Next i
StringInClipboard rngWerte
End Sub


Gruß Uwe
Als Antwort auf diesen Beitrag
Alwin Weisangler
26.05.2026 14:21:07
AW: Problem mit 2-spaltiger Listbox
Hallo StefanK,

durch die Glaskugel: Du nutzt vermutlich Win11 und versuchst via MSForms.DataObject die Zwischenablage zu nutzen. Das wird nur funktionieren, wenn kein Fenster des Dateimanagers (Datei Explorer) geöffnet ist.

Dafür gibt es die Möglichkeit dies via API-Funktion zu regeln.


Gruß Uwe
Folgenachrichten
Antwort auf Beitrag erstellen
Bitte einen Anwendernamen ohne @ eingeben.
Bitte das Passwort eingeben.
Bitte eine gültige E-Mail-Adresse eingeben.
Bitte einen Betreff eingeben.
Weitere Optionen
Aktivieren, wenn die Frage/der Beitrag noch nicht beantwortet wurde und unter Listen > Offene Threads erscheinen soll.
Beispieldatei hochladen

Bitte einen Nachrichtentext eingeben.