CHRIS RAE'S VBA PAGES
|Description:||Self-modifying VBA code|
' Note that the current module ought not to be added to
' as it's already been compiled and new bits aren't recognised. Note also that you
' have to use Application.Run instead of just calling the procedure because otherwise
' VBA generates a compile-time error.
' Chris Rae, 15/10/99.
AddLines "Newmodule", "Sub Test", "msgbox ""hello""", "End Sub"
Sub AddLines(stModuleName As String, ParamArray stLines() As Variant)
Dim inRunThrough As Integer
.Name = stModuleName
For inRunThrough = 0 To UBound(stLines())
.CodeModule.InsertLines .CodeModule.CountOfLines + 1, stLines(inRunThrough)
You're free to use these routines for anything you want - all I ask is that for commercial use you give me credit somewhere. You may instead want to head back to the index for my Visual Basic for Applications Pages or the main routines archive page.