Changing Code Modules, PLEASE HELP ASAP!! PART 2
Did the elements of the myFstr match the code--including upper/lower case?
Brett Smith wrote:
I still wasn't able to get it to replace all of the text. Is there a reason
why it is not replacing the last 3 or 4 variable strings in the array?
"Dave Peterson" wrote:
I'm surprised that it did two.
This is untested, but it did compile.
Option Explicit
Sub ReplacecodeInModule(RepWk As Workbook)
Dim myCode As String
Dim myFStr As Variant
Dim myRStr As Variant
Dim myMod As VBComponent
Dim iCtr As Long
myFStr = Array("XLfit3_", "ExcludePoints", "IncludePoints", _
"XLFitExcludePoint", "XLFitIncludePoint", "YRange")
myRStr = Array("xf4_", "ExcludePoint", "IncludePoint", _
"xf4_ExcludePoint", "xf4_IncludePoint", "RangeY")
For Each myMod In RepWk.VBProject.VBComponents
With myMod.CodeModule
For iCtr = LBound(myFStr) To UBound(myFStr)
If .CountOfLines 0 Then
myCode = .Lines(1, .CountOfLines)
If InStr(1, myCode, myFStr(iCtr)) 0 Then
'MsgBox myCode
myCode = Replace(myCode, myFStr(iCtr), myRStr(iCtr))
'MsgBox myCode
.DeleteLines 1, .CountOfLines
.InsertLines .CountOfLines + 1, myCode
End If
End If
Next iCtr
End With
Next myMod
End Sub
And just to remember, your instr() is case sensitive as written and so is your
replace().
That might be important.
Brett Smith wrote:
I posted a question before and it was answered for the most part. I need to
replace 6 strings all at once, but my code only replaces 2 of the 6
variables. How can I change all 6? Here is the code below. Any help would
be greatly appreciated. Thanks!!
Sub FileSearchforMacros2()
Dim i As Integer
Dim wkbkOne As Workbook
With Application.FileSearch
.LookIn = "\\rnumsriggap06\Abase401\Restempl\652"
.SearchSubFolders = True
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
'MsgBox "There were " & .FoundFiles.Count & _
' "file(s) found."
For i = 1 To .FoundFiles.Count
'MsgBox .FoundFiles(i)
Set wkbkOne = Application.Workbooks.Open( _
.FoundFiles(i), , , , Password:=("INGRAM"))
ReplacecodeInModule wkbkOne
remove_xlfit3_ref wkbkOne
wkbkOne.Save
wkbkOne.Close
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub
------------------------------------------------------------------------------------------
Sub ReplacecodeInModule(RepWk As Workbook)
Dim myCode As String
Dim myFStr As Variant
Dim myRStr As Variant
Dim myMod As VBComponent
myFStr = Array("XLfit3_", "ExcludePoints", "IncludePoints",
"XLFitExcludePoint", "XLFitIncludePoint", "YRange")
myRStr = Array("xf4_", "ExcludePoint", "IncludePoint",
"xf4_ExcludePoint", "xf4_IncludePoint", "RangeY")
For Each myMod In RepWk.VBProject.VBComponents
With myMod.CodeModule
If .CountOfLines 0 Then
myCode = .Lines(1, .CountOfLines)
If InStr(1, myCode, myFStr(i)) 0 Then
'MsgBox myCode
myCode = Replace(myCode, myFStr(i), myRStr(i))
'MsgBox myCode
.DeleteLines 1, .CountOfLines
.InsertLines .CountOfLines + 1, myCode
End If
End If
End With
Next myMod
End Sub
--
Dave Peterson
--
Dave Peterson
|