|
本帖最后由 liucqa 于 2013-6-23 21:40 编辑
Smart Indenter 3.5 for VBA 是个代码缩进工具,在Windows7下面安装,需要以管理员身份运行
http://www.oaltd.co.uk/indenter/default.htm
修改缩进值的方法:
Find key HKEY_CURRENT_USER\Software\Microsoft\VBA\
Right click on the key and add new key "6.0"
Right click on this and add new key "Common"
Right click on this and add new DWORD value "TabWidth"
Double click the value and set it to 2
一个日本人写的缩进工具
http://blog.livedoor.jp/andrewe/archives/51271922.html
MZ-Tools 3.0 是一个快速生成代码的工具,其中的下面功能比较有用:
Close All Windows
Error Handler
Add Module Header
Add Procedure Header
Add Both
Add Code Template
Add and Remove Line Numbers
Procedure Callers
Copy/Paste Multiple Chunks
Erase Immediate Window
http://www.mztools.com/v3/features.aspx
一些VBA老工具,留个记忆:
http://www.cpearson.com/excel/xltools.htm
附一个简易的缩进代码
- Sub miApplyIndent()
- Dim aCodePane As VBIDE.CodePane, aStartLine As Long, aStartColumn As Long
- Dim aEndLine As Long, aEndColumn As Long, aLineNumber As Long
- Dim aLine As String, aIndentLevel As Integer, aLineIsAfterUnderscore As Boolean
- Dim aIncThisIndent As Boolean, aDecThisIndent As Boolean
- Dim aIncNextIndent As Boolean, aDecNextIndent As Boolean
-
- Set aCodePane = ActiveWorkbook.VBProject.VBE.ActiveCodePane
-
- aCodePane.GetSelection aStartLine, aStartColumn, aEndLine, aEndColumn
-
- For aLineNumber = aStartLine To aEndLine
- aLine = aCodePane.CodeModule.Lines(aLineNumber, 1)
- Do Until Left(aLine, 1) <> " "
- aCodePane.CodeModule.ReplaceLine aLineNumber, Mid(aLine, 2)
- aLine = aCodePane.CodeModule.Lines(aLineNumber, 1)
- Loop 'Loop repeats until all spaces/indents removed
- Next aLineNumber
-
- For aLineNumber = aStartLine To aEndLine
- aLine = aCodePane.CodeModule.Lines(aLineNumber, 1)
- Select Case Left(aLine, IIf(InStr(aLine, " ") = 0, 999, InStr(aLine, " ") - 1))
- Case "Do", "For", "Private", "Select", "Sub", "While", "With"
- aIncNextIndent = True 'After certain keywords, indent next line
- Case "If" 'After If, where line ends in Then, indent next line
- If Right(aLine, 4) = "Then" Then aIncNextIndent = True
- Case "Loop", "Next", "End" 'At Loop, Next, End, un-indent this line
- aDecThisIndent = True
- Case "Case", "Else", "ElseIf"
- aDecThisIndent = True 'Un-indent Case or Else
- aIncNextIndent = True 'Indent line after Case or Else
- End Select
-
- If Right(aLine, 2) = " _" And Not aLineIsAfterUnderscore Then
- aIncNextIndent = True 'Indent line after underscore
- aLineIsAfterUnderscore = True 'Set a flag to un-indent the line after next
- ElseIf Right(aLine, 2) <> " _" And aLineIsAfterUnderscore Then
- aDecNextIndent = True
- aLineIsAfterUnderscore = False
- End If
-
- If aIncThisIndent Then aIndentLevel = aIndentLevel + 1: aIncThisIndent = False
- If aDecThisIndent Then aIndentLevel = aIndentLevel - 1: aDecThisIndent = False
- On Error GoTo lIndentError
- aCodePane.CodeModule.ReplaceLine aLineNumber, Space$(aIndentLevel * 4) & aLine
- On Error GoTo 0
- If aIncNextIndent Then aIndentLevel = aIndentLevel + 1: aIncNextIndent = False
- If aDecNextIndent Then aIndentLevel = aIndentLevel - 1: aDecNextIndent = False
- Next aLineNumber
- Exit Sub
- lIndentError:
- If aIndentLevel < 0 Then aIndentLevel = 0 'Will not happen unless extra lines selected
- Resume Next
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|