Thank you all for for advice.
Using addins is a good idea, but for this particular excercise I needed to change the code in the VBE for Sheet1. It turns out there are several locations that needed updates so I can pretty much use the same code, although lesson learned for the future. I found the following code, and modified it slightly and it works as required.
Function CodeRewrite(SheetName As Workbook)
Dim VBP As VBIDE.VBProject
Dim VBC As VBIDE.VBComponent
Dim SL As Long, EL As Long, SC As Long, EC As Long
Dim S As String
Dim Found As Boolean
On Error Resume Next
Set VBP = SheetName.VBProject
On Error GoTo 0
If VBP Is Nothing Then
MsgBox "Your security settings do not allow this macro to run.", vbInformation
Exit Function
End If
For Each VBC In VBP.VBComponents
If VBC.Type = vbext_ct_Document Then
If InStr(1, VBC.Name, "ThisWorkbook", vbTextCompare) = 0 Then
If VBC.Name = "Sheet1" Then
With VBC.CodeModule
SL = 1 ' Start Line
SC = 1 ' Start Column
EL = .CountOfLines ' End Line
EC = 999 ' End Column
Found = .Find("Find This String", SL, SC, EL, EC, True, False, False)
If Found = True Then
S = .Lines(SL, 1)
S = Replace(S, _
"Find This String", _
"Replace With This String", 1, -1, vbTextCompare)
Debug.Print S
.ReplaceLine SL, S
End If
End With
Exit Function
End If
End If
End If
Next VBC
End Function
Thanks to all who provided advice.
Cheers
Bookmarks