Notizen und Clipboard
Teil 1: Code zur Handhabung von Notizen
Oft möchte man per VBA eine Notiz zu einer Zelle eintragen oder die Notiz einer Zelle auslesen.
Z.B. Wozu der Termin ist, oder was hinter einer Bezeichnung steht, oder ein Hinweis wo man mehr Informationen findet.
Ihr kennt vieleicht noch andere praktische Anwendungen.
Variablen:
Dim strNotiz as String ' Der Text der als Notiz zu bearbeiten ist (könnte auch der Inhalt einer Textbox sein)
Dim lngZ as long 'Pointer auf Zelle (Zeile)
Dim lngCol as long 'Pointer auf Zelle (Spalte oder column)
strNotiz = TxtNotiz 'Textbox.Text in die Variable strNotiz eintragen
Public Sub Notiz_eintragen(lngZ As Long, lngCol As Long)
With ActiveSheet 'Aktuelle Tabelle
.Cells(lngZ, lngCol).ClearComments 'Notiz löschenIf strNotiz = "" Then Exit Sub 'kein Text zum EintragenIf bolNotiz = True Then
.Cells(lngZ, lngCol).AddComment strNotiz.Cells(lngZ, lngCol).Comment.Shape.TextFrame.AutoSize = True
End If
End WithTxtNotiz = strNotiz
End Sub
Public Sub Notiz_Einlesen(lngZ As Long, lngCol As Long)
With ActiveSheet
If .Cells(lngZ, lngCol).Comment Is Nothing Then 'Keine Notiz zum Einlesen
strNotiz = ""bolNotiz = False
Else
strNotiz = ActiveSheet.Cells(lngZ, lngCol).Comment.TextbolNotiz = True
End If
End SubEnd With
TxtNotiz = strNotiz ' Variable strNotiz zu Textbox.Text eintragen
Teil 2: Texaustausch mit Zwischenspeicher (Clipboard)
In vielen Anwendungen möchte man vorhandener Text via Zwischenspeicher in ein anderes Dokument verschieben.
Hier von Webseite zu Excel Textboxen oder umgekehrt.
Auch dazu bietet VBA eine Lösung die Ich Ihnen zur vorstellen möchte.
Das Beispiel benutzt zwei Tasten (cmdTxtToClipboard & cmdClipboardToTxt)
und eine Textbox die txtClipboard heisst.
Variablen:
Dim strTextClip as String ' Variable für Text von und zur Zwischenablage
strTextClip = txtClipboard.Text 'Textquelle ist hier die TextBox
Private Sub cmdTxtToClipboard_Click()
'Text in Zwischenablage speichernOn Error GoTo ErrorClipboardDim myData As New DataObjectmyData.SetText strTextClipmyData.PutInClipboardMsgBox "Gespeichert!", vbInformation + vbOKOnly, "Zwischenablage"Exit Sub 'ErledigtErrorClipboard:MsgBox "Keine Daten von StrTextClip!", vbInformation + vbOKOnly, "Zwischenablage"
End Sub
Private Sub cmdClipboardToTxt_Click()
'Einlesen von der ZwischenablageDim myData As New DataObjectSet myData = New MSForms.DataObjectOn Error GoTo ErrorClipboard 'Wenn kein Text in ZwischenablagemyData.GetFromClipboardstrNotiz = myData.GetText(1)txtClipboard =strNotiz 'Text zu TextboxMsgBox "gelesen", vbInformation + vbOKOnly, "Zwischenablage"Exit Sub 'ErledigtErrorClipboard:MsgBox "Zwischenablage hat keine Daten!", vbInformation + vbOKOnly, "Zwischenablage"
End Sub