Gruppe
Extern
Problem
Die in der Tabelle vorhandenen Kommentare sollen ebenso wie die Zellinhalte - durch öffnende und schließende Klammern gekennzeichnet - in eine Textdatei übernommen werden.
StandardModule: Modul1
Sub Comment2Text()
Dim cmt As Comment
Dim rng As Range
Dim iRow As Integer, iCol As Integer
Dim sTxt As String
On Error GoTo ERRORHANDLER
Set rng = Range("A1").CurrentRegion
Open Application.Path & "\test.txt" For Output As #1
For iRow = 1 To rng.Rows.Count
For iCol = 1 To rng.Columns.Count
If Not Cells(iRow, iCol).Comment Is Nothing Then
sTxt = sTxt & Cells(iRow, iCol).Text & _
"(" & Cells(iRow, iCol).Comment.Text & ")" & ";"
Else
sTxt = sTxt & Cells(iRow, iCol).Text & ";"
End If
Next iCol
sTxt = Left(sTxt, Len(sTxt) - 1)
Print #1, sTxt
sTxt = ""
Next iRow
Close
MsgBox "Textdatei wurde erstellt!"
Exit Sub
ERRORHANDLER:
MsgBox "Textdatei konnte nicht erstellt werden!"
End Sub