problem with Smart Indenter

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
2,056
Office Version
  1. 365
Platform
  1. Windows
Hi all, I am in a new work environment (again) and just went to load Smart Indenter to pretty up my lousy looking macros. However, i keep getting "corrupt installation" as a fatal error. Has anybody else seen this recently or has anybody got an alternative that i can use?

ajm
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Are you trying indent your code only?

Save code below as add-in. This is wot I use indent my code
Code:
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
 
Upvote 0

Forum statistics

Threads
1,224,809
Messages
6,181,076
Members
453,020
Latest member
mattg2448

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top