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