<div align="left">Hi,
I am designing an add-in which requires me to loop through all the modules in a
VB project and apply functions to them. I have not been able to find any examples of code that do this, so this has been my best guess. I also have not found a good way to debug add-ins, so I have to constantly compile the dll each time and then open up a new instance of
VB to run it, however I still am unable to debug the add-in. Any ideas? Ok, back to the code. I placed msgbox's displaying the names of the components in the project as it loops through them and it appears to be looping through all of them, however I'm not sure if I am missing some code since the function is only being applied to 2 out of 10 modules. Could this be a problem with my function or this code that selects the modules and activates them?
Code:
Set Proj = .ActiveVBProject
Set Comp = Proj.VBComponents
TotalModules = .ActiveVBProject.VBComponents.Count
MsgBox "There is a total of " & TotalModules & " modules"
For Each Comp In Proj.VBComponents
'Activate new module
Set Pane = Comp.CodeModule.CodePane
Pane.Show
' lock screen from updating
LockWindow True, , .MainWindow.Caption
' get the starting procedure line count
HeaderCount = .ActiveCodePane.CodeModule.CountOfDeclarationLines
' set us at the starting procedure
.ActiveCodePane.SetSelection HeaderCount + 1, 1, HeaderCount + 1, 1
' show progress
frmInfo.ResetProgressBar
frmInfo.Show
frmInfo.Refresh
Do Until Counter > .ActiveCodePane.CodeModule.CountOfLines
' find out what line we are at
.ActiveCodePane.GetSelection TempStartLine, TempStartColumn, TempEndLine, TempEndColumn
' find out where the next procedure is and get the current procedure info
NextMemberLineStart = GetMemberInfo(TempStartLine)
' do what has been selected by user
Select Case ButtonCaption
Case "Comment All Procedures"
' add comment separators to all procedures
frmInfo.ProgressMessage "Now adding comments to all procedures", "Comment All Procedures"
NextMemberLineStart = AddComments(ProcName, ProcType, ProcComment)
frmInfo.UpdateProgressBar TempStartLine - HeaderCount, .ActiveCodePane.CodeModule.CountOfLines - HeaderCount
'Exit Do
Case "Indent All Procedures"
' indent all code in current module
frmInfo.ProgressMessage "Now indenting all procedures", "Indenting All Procedures"
IndentCode ProcBodyStartLine, ProcBodyEndLine
frmInfo.UpdateProgressBar TempStartLine - HeaderCount, .ActiveCodePane.CodeModule.CountOfLines - HeaderCount
'Exit Do
Case "Spell Check - Quotes and Comments"
' spell check quotes and comments in current code module
SpellCheck
'Exit Do
Case "Add Line Numbers"
' remove old line numbers, reindent the code and add new line numbers
frmInfo.ProgressMessage "Now adding line numbers to all procedures", "Add Line Numbers To All Procedures"
RemoveLineNumbers ProcBodyStartLine, ProcBodyEndLine
IndentCode ProcBodyStartLine, ProcBodyEndLine
AddLineNumbers ProcBodyStartLine, ProcBodyEndLine
frmInfo.UpdateProgressBar TempStartLine - HeaderCount, .ActiveCodePane.CodeModule.CountOfLines - HeaderCount
Case "Remove Line Numbers"
' remove old line numbers and reindent the code
frmInfo.ProgressMessage "Now removing line numbers from all procedures", "Remove Line Numbers From All Procedures"
RemoveLineNumbers ProcBodyStartLine, ProcBodyEndLine
IndentCode ProcBodyStartLine, ProcBodyEndLine
frmInfo.UpdateProgressBar TempStartLine - HeaderCount, .ActiveCodePane.CodeModule.CountOfLines - HeaderCount
End Select
' set us at the starting line of the next procedure
.ActiveCodePane.SetSelection NextMemberLineStart, 1, NextMemberLineStart, 1
' increment our line counter
Counter = NextMemberLineStart
Loop
Pane.Window.Close
'loop through code modules
Next Comp
' hide progressbar
frmInfo.Hide
' unlock screen for updating
LockWindow False, , .MainWindow.Caption
Any example code/suggestions would be appreciated.
Thanks :)</div id="left">