AW: ActiveCell = ActiveCell & ", " & ActiveSheet.Paste
04.07.2010 09:22:22
fcs
Hallo Karsten,
hier 2 Varianten.
Variante 2 fügt alle Varianten von Textinhalten in der Zwischenablage ein.
In Variante 1 kann man ggf. über die Art des Zwischenablage-Inhalts Aktionen steuern. In Excel muss dabei noch berücksichtigt werden, dass im Kopiermodus für eine Zelle der Text in der Zwischenablage noch eine Zeilenschaltung beinhaltet.
Gruß
Franz
Sub CopyAnfuegen_1()
'ggf. im Excel-VBA-Editor unter Extras-Verweise den Verweis auf die _
Microsoft Forms x.y Object Library aktivieren
Dim MyData As New MSForms.DataObject
Dim sText, oFormat As Variant, bolAnfuegen As Boolean
For Each oFormat In Application.ClipboardFormats
Select Case oFormat
Case 0, 1, 7, 12, 14
'0 = xlClipboardFormatText Text
'1 = xlClipboardFormatVALU Wert
'5 = xlClipboardFormatCSV CSV-Format
'7 = xlClipboardFormatRTF RTF-Format
'12 = xlClipboardFormatDspText DSP-Textformat
'14 = xlClipboardFormatNative Systemeigenes Format
MyData.GetFromClipboard
sText = MyData.GetText
If Application.CutCopyMode = xlCopy Then 'xlCopy
'Excel ist im Kopiermodus - Zeilenschaltung am Ende entfernen
sText = sText
sText = Mid(sText, 1, Len(sText) - 2)
End If
bolAnfuegen = True
Exit For
Case Else
'do nothing
End Select
Next oFormat
If bolAnfuegen = True Then
ActiveCell = ActiveCell & ", " & sText
Else
MsgBox "Zwischenablage enthält keine anfügbaren Informationen!"
End If
End Sub
Sub CopyAnfuegen_2()
'ggf. im Excel-VBA-Editor unter Extras-Verweise den Verweis auf die _
Microsoft Forms x.y Object Library aktivieren
Dim MyData As New MSForms.DataObject
Dim sText, bolAnfuegen As Boolean
On Error GoTo Fehler
MyData.GetFromClipboard
sText = MyData.GetText
If Application.CutCopyMode = xlCopy Then 'xlCopy
'Excel ist im Kopiermodus - Zeilenschaltung am Ende entfernen
sText = sText
sText = Mid(sText, 1, Len(sText) - 2)
End If
bolAnfuegen = True
Fehler:
If bolAnfuegen = True Then
ActiveCell = ActiveCell & ", " & sText
Else
MsgBox "Zwischenablage enthält keine anfügbaren Informationen!"
End If
End Sub