Does anyone know a way to search and replace a word in VB with VB?
For example... run a macro to search through all the VB contained in a workbook and replace the word orange with the word lemon.
Does anyone know a way to search and replace a word in VB with VB?
For example... run a macro to search through all the VB contained in a workbook and replace the word orange with the word lemon.
Last edited by Mayweed; 03-14-2011 at 08:03 AM.
![]()
Sub snb() For Each cp In ActiveWorkbook.VBProject.VBComponents With cp.CodeModule If .countoflines > 0 Then c02 = Replace(.Lines(1, .countoflines), "Lemon", "orange") .DeleteLines 1, .countoflines .AddFromString c02 End If End With Next End Sub
Thanks Snb but I can't get it to work, I've attached a workbook to demonstrate what I mean.
After running one macro, all messages containing the word 'Lemon' should read 'Orange'.
You can't put this code in the same workbook you want to adapt.
Ahhh. now I've got it. Thanks Snb, just what I wanted.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks