-
Notifications
You must be signed in to change notification settings - Fork 0
/
RemoveComments.bas
52 lines (40 loc) · 1.42 KB
/
RemoveComments.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Attribute VB_Name = "RemoveComments"
'activate from referance Microsoft Visual Basic for Applications Extensibility 5.3.
Sub RemoveAllComments()
Dim vbProj As Object
Dim vbComp As Object
Dim vbMod As Object
Dim i As Long
Dim lineText As String
Dim lineCount As Long
Set vbProj = ThisWorkbook.VBProject
' Check if the reference is already added
Dim ref As Object
Dim refFound As Boolean
refFound = False
For Each ref In vbProj.References
If ref.Name = "VBIDE" Then
refFound = True
Exit For
End If
Next ref
' Add the reference if not already added
If Not refFound Then
vbProj.References.AddFromGuid "{0002E157-0000-0000-C000-000000000046}", 5, 3
MsgBox "Microsoft Visual Basic for Applications Extensibility 5.3 reference added."
Else
' MsgBox "Reference is already added."
End If
Set vbProj = ActiveWorkbook.VBProject
For Each vbComp In vbProj.VBComponents
Set vbMod = vbComp.CodeModule
lineCount = vbMod.CountOfLines
For i = lineCount To 1 Step -1
lineText = vbMod.lines(i, 1)
If Trim(lineText) Like "'*" Then
vbMod.DeleteLines i
End If
Next i
Next vbComp
MsgBox "All comments removed from the VBA project.", vbInformation
End Sub