Replacing code at runtime
Ajit,
Presuming you know the module name, you can use cod elike the macro below,
which will require a reference to MS VBA Extensibility. This also assumes
that the line you're looking for is unique.
HTH,
Bernie
MS Excel MVP
Sub AddLineAfterExistingCode()
Dim myCode As String
Dim OldCode As String
Dim NewCode As String
OldCode = "MsgBox ""Hello"""
NewCode = "MsgBox ""Hello There"""
With ActiveWorkbook.VBProject.VBComponents.Item("Module Name").CodeModule
myCode = .Lines(1, .CountOfLines)
myCode = Replace(myCode, OldCode, OldCode & Chr(10) & NewCode)
..DeleteLines 1, .CountOfLines
..InsertLines .CountOfLines + 1, myCode
End With
End Sub
"Ajit" wrote in message
...
This forum had been of great help at all the times..
I have posted this issue before too..but may be I could not explain
properly...trying to give another shot.
I have couple of templates and i need to add a line of code to all of them
(to the same procedure in a same module)...i am able to find the procedure
and add a line of code at the end. But what if i had to do find some code
and
add it in next line....I am not able to find the linenumber of the code
that
i do find for.
Suggestions will be greatly appreciated.
Thanks,
--
Ajit
|