[VBA ] 請問去除所有 module comments 的原理

看板Visual_Basic作者 (gecer)時間11年前 (2014/10/19 18:31), 編輯推噓0(002)
留言2則, 1人參與, 最新討論串1/1
小弟不太懂下面這一段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://www.ptt.cc/bbs/Visual_Basic/M.1413714705.A.4D1.html

10/20 21:49, , 1F
你知道 ' 在 VB 裡的用途吧
10/20 21:49, 1F

10/20 21:50, , 2F
隨便找個10列的VB程式 手動跑一遍不就知道了
10/20 21:50, 2F
文章代碼(AID): #1KGvCHJH (Visual_Basic)
文章代碼(AID): #1KGvCHJH (Visual_Basic)