Option Explicit
Public WithEvents DCEvtModule As VBIDE.CommandBarEvents
Public WithEvents DCEvtProject As VBIDE.CommandBarEvents
Public WithEvents DLEvtModule As VBIDE.CommandBarEvents
Public WithEvents DLEvtProject As VBIDE.CommandBarEvents
Dim rCount As Integer, Lentemp As Integer, i As Integer
Dim Strtemp As String, ftemp As String
Dim Vbc As VBComponent
Private Sub EvtHandler_Click(ByVal CommandBarControl As Object, handled As Boolean, CancelDefault As Boolean)
On Error Resume Next
handled = True
CancelDefault = True
End Sub
Private Sub DCEvtModule_Click(ByVal CommandBarControl As Object, handled As Boolean, CancelDefault As Boolean)
'套用目前模組
With Application.VBE.ActiveCodePane.CodeModule
rCount = .CountOfLines
If rCount > 0 Then
For i = rCount To 1 Step -1
Lentemp = Len(.Lines(i, 1)) '判斷是否為空行
If Lentemp > 0 Then
ftemp = InStr(1, .Lines(i, 1), "'") '尋找註解的位置
If ftemp > 0 Then
If ftemp = 1 Then '註解在第一行
Strtemp = ""
.DeleteLines i
Else
'註解符號前一個字元為空格,才能確保是註解符號
If Mid(.Lines(i, 1), ftemp - 1, ftemp - 1) = " " Then
Strtemp = Mid(.Lines(i, 1), 1, ftemp - 1)
.ReplaceLine i, Strtemp '取代字串(清除註解)
End If
End If
End If
End If
Next i
End If
End With
End Sub
Private Sub DCEvtProject_Click(ByVal CommandBarControl As Object, handled As Boolean, CancelDefault As Boolean)
'套用專案中所有的模組
For Each Vbc In ActiveWorkbook.VBProject.VBComponents
With Vbc.CodeModule
rCount = .CountOfLines
If rCount > 0 Then
For i = rCount To 1 Step -1
Lentemp = Len(.Lines(i, 1)) '判斷是否為空行
If Lentemp > 0 Then
ftemp = InStr(1, .Lines(i, 1), "'") '尋找註解的位置
If ftemp > 0 Then
If ftemp = 1 Then '註解在第一行
Strtemp = ""
.DeleteLines i
Else
'註解符號前一個字元為空格,才能確保是註解符號
If Mid(.Lines(i, 1), ftemp - 1, ftemp - 1) = " " Then
Strtemp = Mid(.Lines(i, 1), 1, ftemp - 1)
.ReplaceLine i, Strtemp '取代字串(清除註解)
End If
End If
End If
End If
Next i
End If
End With
Next Vbc
End Sub
Private Sub DLEvtModule_Click(ByVal CommandBarControl As Object, handled As Boolean, CancelDefault As Boolean)
'套用目前模組
With Application.VBE.ActiveCodePane.CodeModule
rCount = .CountOfLines
For i = rCount To 1 Step -1
Lentemp = Len(.Lines(i, 1)) '判斷是否為空行
If Lentemp = 0 Then
.DeleteLines i
End If
Next i
End With
End Sub
Private Sub DLEvtProject_Click(ByVal CommandBarControl As Object, handled As Boolean, CancelDefault As Boolean)
'套用專案中所有的模組
For Each Vbc In ActiveWorkbook.VBProject.VBComponents
With Vbc.CodeModule
rCount = .CountOfLines
For i = rCount To 1 Step -1
Lentemp = Len(.Lines(i, 1)) '判斷是否為空行
If Lentemp = 0 Then
.DeleteLines i
End If
Next i
End With
Next Vbc
End Sub
檔案下載:http://www.chijanzen.twmail.net/VBAFILE/vbe/F0009.htm