DimGR
05-03-2022, 05:06 AM
Hi,
I am trying to create a VBA that will:
-find and replace a specific string
-in all other VBAs of the same workbook
-any number of time(s), in any part(s) and any VBA(s) it appears
I have found this example, but it replaces the whole line, instead of the desired string only:
Sub replaceConstant()
Dim project As VBIDE.VBProject
For Each project In Application.VBE.VBProjects
Dim codeMod As VBIDE.CodeModule
Dim component As VBIDE.VBComponent
For Each component In project.VBComponents
If component.Name <> "replaceConstant" Then
Set codeMod = component.CodeModule
Dim startline As Long
startline = 1
codeMod.Find Target:="Old_Text", _
startline:=startline, startcolumn:=1, endline:=codeMod.CountOfLines, endcolumn:=1
codeMod.ReplaceLine startline, "New_text"
End If
Next component
Next project
End Sub
Could you please help me?
I am trying to create a VBA that will:
-find and replace a specific string
-in all other VBAs of the same workbook
-any number of time(s), in any part(s) and any VBA(s) it appears
I have found this example, but it replaces the whole line, instead of the desired string only:
Sub replaceConstant()
Dim project As VBIDE.VBProject
For Each project In Application.VBE.VBProjects
Dim codeMod As VBIDE.CodeModule
Dim component As VBIDE.VBComponent
For Each component In project.VBComponents
If component.Name <> "replaceConstant" Then
Set codeMod = component.CodeModule
Dim startline As Long
startline = 1
codeMod.Find Target:="Old_Text", _
startline:=startline, startcolumn:=1, endline:=codeMod.CountOfLines, endcolumn:=1
codeMod.ReplaceLine startline, "New_text"
End If
Next component
Next project
End Sub
Could you please help me?