AW: Code in Code einfügen
19.12.2005 16:46:04
Richard
hallo,
ich hab mal sowas ähnliches gemacht um kommentare zu löschen. das ging mit den befehlen insertlines und deletelines
vielleicht hilft dir das ja weiter.
gruss
Richard
Sub Delete_Comments(actWBook As String, actSheet As String)
Dim i As Integer, j As Integer, Index As Integer, ipos As Integer
Dim OnlyComment As Boolean
Application.StatusBar = "Delete_Comments"
Index = 0
For i = 1 To Workbooks(actWBook).VBProject.VBComponents.Count
If Workbooks(actWBook).VBProject.VBComponents.Item(i).name = actSheet Then
Index = i
Exit For
End If
Next i
If Index = 0 Then Exit Sub
With Workbooks(actWBook).VBProject.VBComponents.Item(Index).CodeModule
For i = .CountOfLines To 1 Step -1
OnlyComment = True
ipos = InStr(.Lines(i, 1), "'")
If ipos > 0 Then
For j = 1 To ipos - 1
If Mid(.Lines(i, 1), j, 1) <> " " Then OnlyComment = False
Next j
If OnlyComment Then
'if line contains only comments
.DeleteLines (i)
Else
'if line contains code and comments
.InsertLines i, Left(.Lines(i, 1), ipos - 1)
.DeleteLines (i + 1)
End If
End If
If InStr(UCase(.Lines(i, 1)), "OPTION EXPLICIT") Then
.DeleteLines (i)
End If
Next i
'For i = .CountOfLines To 1 Step -1
' If Len(.Lines(i, 1)) = 0 Then
' .DeleteLines (i)
' End If
'Next i
End With
Application.StatusBar = ""
End Sub