Gruppe
Ereignis
Problem
Bei Doppelklick auf eine Zelle soll aus einer Textdatei ein zugehöriger Hilfetext aus- und in einen Kommentar eingelesen werden.
ClassModule: Tabelle1
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim cmt As Comment
Dim sHelp As String, sTxt As String, sFile As String
If Intersect(Target, Range("A1:C1")) Is Nothing Then Exit Sub
Cancel = True
sFile = ThisWorkbook.Path & "\12help" & Target.Column & ".txt"
If Dir(sFile) = "" Then
sHelp = "Keine Hilfedatei gefunden!"
Else
Close
Open sFile For Input As #1
Do Until EOF(1)
Line Input #1, sTxt
sHelp = sHelp & sTxt & vbLf
Loop
Close
End If
If Not ActiveCell.Comment Is Nothing Then
ActiveCell.Comment.Delete
End If
Application.DisplayCommentIndicator = xlCommentAndIndicator
Set cmt = ActiveCell.AddComment(sHelp)
cmt.Shape.TextFrame.AutoSize = True
End Sub