作者gecer (gecer)
看板Visual_Basic
标题[VBA ] 请问去除所有 module comments 的原理
时间Sun Oct 19 18:31:40 2014
小弟不太懂下面这一段code的原理 请好心大大赐教
http://www.vbaexpress.com/kb/getarticle.php?kb_id=266
Option Explicit
Sub Macro1()
Dim n As Long
Dim i As Long
Dim j As Long
Dim k As Long
Dim l As Long
Dim LineText As String
Dim ExitString As String
Dim Quotes As Long
Dim q As Long
Dim StartPos As Long
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
StartPos = 1
Retry:
n = InStr(StartPos, LineText, "'")
q = InStr(StartPos, LineText, """")
Quotes = 0
If q < n Then
For l = 1 To n
If Mid(LineText, l, 1) = """" Then
Quotes = Quotes + 1
End If
Next l
End If
If Quotes = Application.WorksheetFunction.Odd(Quotes) Then
StartPos = n + 1
Goto Retry:
Else
Select Case n
Case Is = 0
Case Is = 1
.DeleteLines j, 1
Case Is > 1
.ReplaceLine j, Left(LineText, n - 1)
End Select
End If
Next j
End With
Next i
ExitString = "Ignore Comments In This Module"
End Sub
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 111.255.7.108
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/Visual_Basic/M.1413714705.A.4D1.html
1F:→ MOONRAKER: 你知道 ' 在 VB 里的用途吧 10/20 21:49
2F:→ MOONRAKER: 随便找个10列的VB程式 手动跑一遍不就知道了 10/20 21:50