ich habe noch eine kleine Frage.
Ich möchte gerne einen Wert aus der Zwischenablage in eine Variable schreiben.
Wie kann ich das denn machen?
Vielen Dank schonmal
Beste Grüße
Sebastian
Public Function GetTextFromClipBoard1() As String
Dim workSheet1 As Worksheet
Dim range1 As Range
Dim formats As Variant
Dim format As Variant
Dim text As String
Application.ScreenUpdating = False
Workbooks.Add
Set range1 = ActiveSheet.Range("a1")
formats = Application.ClipboardFormats
text = ""
For Each format In formats
If (format = xlClipboardFormatText) Then
ActiveSheet.Paste Destination:=range1
Exit For
End If
Next format
If (Not ActiveSheet.UsedRange Is Nothing) Then
Dim row As Range
Dim column As Range
For Each row In ActiveSheet.UsedRange.Rows
For Each column In row.Cells
text = text & column.text
Next column
text = text & vbCrLf
Next row
End If
GetTextFromClipBoard1 = text
ActiveWorkbook.Close savechanges:=False
Application.ScreenUpdating = True
End Function
Public Function GetTextFromClipBoard2() As String
Dim dataObject1 As DataObject ' Tools --> References --> Microsoft Froms 2.0 Object Library
Dim isTextInClipboard As Boolean
Dim text As String
Set dataObject1 = New DataObject
text = ""
' Copies data from the Clipboard to a DataObject
dataObject1.GetFromClipboard
' Returns an integer value indicating whether a specific format is on the DataObject
isTextInClipboard = dataObject1.GetFormat(1)
If (isTextInClipboard) Then
text = dataObject1.GetText(1)
End If
GetTextFromClipBoard2 = text
End Function
Private Sub CommandButton1_Click()
Dim text As String
text = GetTextFromClipBoard1
[a1] = text
End Sub
Private Sub CommandButton2_Click()
Dim text As String
text = GetTextFromClipBoard2
[a1] = text
End Sub
Um den Inhalt der Zwischenablage in eine Variable zu speichern, kannst Du die folgenden VBA-Funktionen verwenden. Hier sind die Schritte:
ALT + F11
, um den VBA-Editor zu öffnen.Einfügen
> Modul
.Public Function GetTextFromClipBoard1() As String
Dim workSheet1 As Worksheet
Dim range1 As Range
Dim formats As Variant
Dim format As Variant
Dim text As String
Application.ScreenUpdating = False
Workbooks.Add
Set range1 = ActiveSheet.Range("a1")
formats = Application.ClipboardFormats
text = ""
For Each format In formats
If (format = xlClipboardFormatText) Then
ActiveSheet.Paste Destination:=range1
Exit For
End If
Next format
If (Not ActiveSheet.UsedRange Is Nothing) Then
Dim row As Range
Dim column As Range
For Each row In ActiveSheet.UsedRange.Rows
For Each column In row.Cells
text = text & column.Text
Next column
text = text & vbCrLf
Next row
End If
GetTextFromClipBoard1 = text
ActiveWorkbook.Close SaveChanges:=False
Application.ScreenUpdating = True
End Function
Public Function GetTextFromClipBoard2() As String
Dim dataObject1 As DataObject ' Tools --> References --> Microsoft Forms 2.0 Object Library
Dim isTextInClipboard As Boolean
Dim text As String
Set dataObject1 = New DataObject
text = ""
' Kopiert Daten von der Zwischenablage in ein DataObject
dataObject1.GetFromClipboard
' Überprüft, ob ein bestimmtes Format im DataObject vorhanden ist
isTextInClipboard = dataObject1.GetFormat(1)
If (isTextInClipboard) Then
text = dataObject1.GetText(1)
End If
GetTextFromClipBoard2 = text
End Function
Private Sub CommandButton1_Click()
Dim text As String
text = GetTextFromClipBoard1
[A1] = text
End Sub
Private Sub CommandButton2_Click()
Dim text As String
text = GetTextFromClipBoard2
[A1] = text
End Sub
Fehler: "Objekt nicht gefunden"
Microsoft Forms 2.0 Object Library
aktiviert hast. Gehe zu Extras
> Verweise
und aktiviere die Bibliothek.Fehler: Der Inhalt der Zwischenablage ist leer
Eine andere Methode, um den Inhalt der Zwischenablage in eine Excel-Variable zu speichern, ist die Verwendung von Application.CutCopyMode
. Diese Methode kann jedoch weniger flexibel sein und funktioniert möglicherweise nicht in allen Szenarien.
Angenommen, Du hast einen Text in Word oder einem anderen Dokument kopiert und möchtest diesen in Excel verwenden:
Du kannst die Funktionen auch anpassen, um den Text in eine andere Zelle zu schreiben oder ihn weiter zu verarbeiten.
1. Wie kann ich die Inhalte der Zwischenablage in eine Excel-Textvariable speichern?
Du kannst die oben beschriebenen VBA-Funktionen verwenden, um den Inhalt der Zwischenablage direkt in eine Variable zu speichern.
2. Funktioniert das in allen Excel-Versionen?
Die beschriebenen Methoden sind in den meisten modernen Excel-Versionen (Excel 2010 und höher) anwendbar. Stelle sicher, dass die Microsoft Forms 2.0 Object Library aktiviert ist.
Die erweiterte Suchfunktion hilft dir, gezielt die besten Antworten zu finden
Suche nach den besten AntwortenEntdecke unsere meistgeklickten Beiträge in der Google Suche
Top 100 Threads jetzt ansehen