Is there a way to run a script that takes all the comments in my excel vba modules off?
I mean both. The comments alone in a row as well as the comments in the same row as code.
Is there a way to run a script that takes all the comments in my excel vba modules off?
I mean both. The comments alone in a row as well as the comments in the same row as code.
Best Regards,
Carlos Paleo.
To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.
If Debugging is harder than writing a program and your code is as good as you can possibly make
it, then by definition you're not smart enough to debug it.
http://www.mugrs.org
Do you want to delete the comments or just remove the ' ?
Not just remove the ', because this would lead to an error as the comment would become part of the code. I want to delete all the comments.
Best Regards,
Carlos Paleo.
To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.
If Debugging is harder than writing a program and your code is as good as you can possibly make
it, then by definition you're not smart enough to debug it.
http://www.mugrs.org
Ok, try this macro:
Option Explicit Sub Macro1() Dim n As Long Dim i As Long Dim j As Long Dim k As Long Dim LineText As String Dim ExitString As String ExitString = "Ignore Comments In This Module" For i = 1 To ActiveWorkbook.VBProject.VBComponents.Count With ActiveWorkbook.VBProject.VBComponents(i).CodeModule For j = 1 To .CountOfLines LineText = Trim(.Lines(j, 1)) If LineText = "ExitString = " & _ """" & "Ignore Comments In This Module" & """" Then Exit For End If n = InStr(1, LineText, "'") Select Case n Case Is = 0 'No Comment Case Is = 1 .ReplaceLine j, "" Case Is > 1 .ReplaceLine j, Left(LineText, n - 1) End Select Next j End With Next i End Sub
Gee man, you ARE great.
I will test it too and let you know.
Best Regards,
Carlos Paleo.
To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.
If Debugging is harder than writing a program and your code is as good as you can possibly make
it, then by definition you're not smart enough to debug it.
http://www.mugrs.org
Sounds good. Let me know if there are any problems.
Take Care
Here is a variation if you want to completely delete a line if it is all comments instead of leaving a blank line.
Option Explicit Sub Macro1() Dim n As Long Dim i As Long Dim j As Long Dim k As Long Dim LineText As String Dim ExitString As String For i = 1 To ActiveWorkbook.VBProject.VBComponents.Count With ActiveWorkbook.VBProject.VBComponents(i).CodeModule For j = .CountOfLines To 1 Step -1 LineText = Trim(.Lines(j, 1)) If LineText = "ExitString = " & _ """" & "Ignore Comments In This Module" & """" Then Exit For End If n = InStr(1, LineText, "'") Select Case n Case Is = 0 Case Is = 1 .DeleteLines j, 1 Case Is > 1 .ReplaceLine j, Left(LineText, n - 1) End Select Next j End With Next i ExitString = "Ignore Comments In This Module" End Sub
Gee DRJ,
are you reading my mind?? I was trying to do that, .
Many thanks again.
Best Regards,
Carlos Paleo.
To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.
If Debugging is harder than writing a program and your code is as good as you can possibly make
it, then by definition you're not smart enough to debug it.
http://www.mugrs.org
Yeah I figured that you would probably want to actually delete the lines.
Take Care