Saturday, 8 October 2016

Indent Vba Code:

Easiest way to indent or tweak what to indent with the below code. Below code indents each line of code where ever it finds the key words. Ofcourse the code doesn't indent the code 100%.

codeFile.txt: File contains the Vba code
Result.txt: File will contain the indented code.


Sub IndentVba()
Dim tabChar As Long
tabChar = 0
Open "C:\Users\jack\Desktop\codeFile.txt" For Input As #1
Open "C:\Users\jack\Desktop\Result.txt" For Output As #2

 r = 1
 Do Until EOF(1)
 Line Input #1, a
 If Trim(a) Like "For *" Or Trim(a) Like "Do *" Or Trim(a) Like "While *" Then
 tabChar = tabChar + 1
 Debug.Print Application.WorksheetFunction.Rept(vbTab, tabChar) & Trim(a)
 Print #2, Application.WorksheetFunction.Rept(vbTab, tabChar) & Trim(a)
 ElseIf Trim(a) Like "Next*" Or Trim(a) Like "Loop*" Then
 Debug.Print Application.WorksheetFunction.Rept(vbTab, tabChar) & Trim(a)
 Print #2, Application.WorksheetFunction.Rept(vbTab, tabChar) & Trim(a)
 If tabChar > 0 Then tabChar = tabChar - 1
 ElseIf Trim(a) Like "End*" Then
 tabChar = 0
 Else
 Debug.Print Application.WorksheetFunction.Rept(vbTab, tabChar) & Trim(a)
 Print #2, Application.WorksheetFunction.Rept(vbTab, tabChar) & Trim(a)
 End If
 Loop
 Close #2
 Close #1
End Sub

Sunday, 22 March 2015

Learn VBA Online


If your domain is related to Data Mining or Management Information System ( MIS) or Analytics or need to create small Automation's to make day to day activities easier. Here is an opportunity to learn Microsoft Visual Basic for Application (VBA) @ very nominal fee.

Please Email or call me for further details.


The Best opportunity for Beginners & Students.
** Live classes no recorded videos