Code to find and replace within code - Board dont fail me now :)

papami

New Member
Joined
Feb 11, 2005
Messages
1
Hello,

This is way beyond my capability so i'm hoping for some help. I have code in a workbook that is distributed amongst our sales force. So there are 50 or so workbooks floating around. I need to find and replace a string withing the existing module and need to do so via a macro. So basically run the macro, its searches the lines of code (close to 5,000 lines) finds the string and replaces it. Here is what Im working with but it does not seem to working well at all

Sub SearchCodeModule()
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim FindWhat As String
Dim SL As Long ' start line
Dim EL As Long ' end line
Dim SC As Long ' start column
Dim EC As Long ' end column
Dim Found As Boolean
Dim Replace As Boolean

Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents("mdlTool_AOP")
Set CodeMod = VBComp.CodeModule

FindWhat = "FY 2012 Budget 1 Field"

With CodeMod
SL = 4306
EL = 4335
SC = 1
EC = 255
Found = .Find(target:=FindWhat, StartLine:=SL, StartColumn:=SC, _
EndLine:=EL, EndColumn:=EC, _
wholeword:=True, MatchCase:=False, patternsearch:=False)

Replacewith = ("FY 2012 Budget 2 Field")

'Do Until Found = False

'Loop
End With
End Sub

When I run the code it says its running but never ends. Seems like its looping over and over. Im pretty lost on this one
The module name in the workbook that needs to be searched is "mdlTool_AOP". Any help would be greatly appreciated
 
Last edited:

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,216,575
Messages
6,131,501
Members
449,654
Latest member
andz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top