View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Howard31[_3_] Howard31[_3_] is offline
external usenet poster
 
Posts: 28
Default Automatically Deleting Comments In VBA

Sorry my previous code wouldn't work, copy and paste the following, I made a
few changes
Dont put this Sub in the same code module from which you want to get rid of
comments.
---------------------------------
Sub ClearAllComments()
Dim TheMod As VBComponent, i As Integer, x As Integer, LastLine As
Integer

Set TheMod = ThisWorkbook.VBProject.VBComponents("MyModuleName" )

LastLine = TheMod.CodeModule.CountOfLines

For i = LastLine To 1 Step -1
For x = 1 To Len(TheMod.CodeModule.Lines(i, 1))
If Mid(TheMod.CodeModule.Lines(i, 1), x, 1) < " " Then
If Mid(TheMod.CodeModule.Lines(i, 1), x, 1) = "'" Then
TheMod.CodeModule.DeleteLines i, 1
Exit For
Else
Exit For
End If
End If
Next x
Next i
End Sub


--
A. Ch. Eirinberg
"Howard31" wrote in message
...
Try the following code, it will work only on comments which are not on the
same line as code

Sub ClearAllComments()
Dim App As Application, i As Integer, x As Integer, LastLine As Integer
Set App = Application
Dim ThisMod As VBComponent

Set ThisMod = ThisWorkbook.VBProject.VBComponents("MyModuleName" )

LastLine = ThisMod.CodeModule.CountOfLines

For i = 1 To LastLine
For x = 1 To Len(ThisMod.CodeModule.Lines(i, 1))
If Mid(ThisMod.CodeModule.Lines(i, 1), x, 1) < "" Then
If Mid(ThisMod.CodeModule.Lines(i, 1), x, 1) = "'" Then
ThisMod.CodeModule.DeleteLines i, 1
Exit For
End If

End If
Next x
Next i
End Sub

Hope this helps

--
A. Ch. Eirinberg
"Dennis Tucker" wrote in message
...
Is there any tool available to automatically strip only the comments from
a VBA project?

Dennis