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
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: