I am formatting excel workbooks from a VB app and I need to perform a search and replace on one of the macro/modules in the worksheet. I cannot find the way to call the module/macro collection that lets me edit them.
You need a reference to VBA Extensibility library.
Here an example how to add a line to a "Module1"
[tt]Dim cMod As VBComponent
Set cMod = ThisWorkbook.VBProject.VBComponents.Item("Module1"
With cMod.CodeModule
.InsertLines .CountOfLines + 1, "' new line"
End With[/tt]
You can use ProcStartLine, ProcCountLines properties of CodeModule object to find procedure, InsertLines, RepLaceLines, DeleteLine to edit code.
See VBA help for details.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.