'Identifying Column G value and replace text in F column
Const FromValue = "Y|LEARN MORE,30|LEARN MORE,Y|GET A QUOTE,Y|RECALL A QUOTE,C|LEARN MORE,50|GET A QUOTE,C|GET A QUOTE,C|RECALL A QUOTE"
fromval=Split(FromValue,",")
Const ToValue = "MobiRoot_TextObject"
dateStamp = Now()
Set WshShell = CreateObject("WScript.Shell")
sPath = WshShell.CurrentDirectory
Set fso = CreateObject("Scripting.FileSystemObject")
Set oExcelApp = CreateObject("Excel.Application")
Set objFsoLog = CreateObject("Scripting.FileSystemObject")
sLogFileName=sPath &"\LogFile-" &DatePart("d", Now) & "-" & DatePart("m", Now) & "-" & DatePart("yyyy", Now) &"-" & DatePart("n", Now) &".txt"
Set logOutput = objFsoLog.CreateTextFile(sLogFileName)
'Set logOutput = objFsoLog.OpenTextFile(sLogFileName, 8, True)
count=0
Dim WshShell, strCurDir
Set ObjFolder = fso.GetFolder(sPath)
Set ObjFiles = ObjFolder.Files
For Each ObjFile In ObjFiles
If LCase(Right(ObjFile.Name, 5)) = ".xlsx" Or LCase(Right(ObjFile.Name, 4)) = ".xls" Then
Count=Count+1
With oExcelApp
.Visible = False
.DisplayAlerts = False
Set oWB = .Workbooks.Open(ObjFile)
End With
Set oWS = oWB.Sheets(1)
logOutput.WriteLine(Replace(Replace(ObjFile,sPath,""),"\","-----"))
For j=0 to ubound(fromval)
For i=1 to 200
Row="G"&i
if oWS.Range(Row).Value = fromval(j) then
Column="F"&i
Preval=oWS.Range(Column).Value
oWS.Range(Column).Value=ToValue
logOutput.WriteLine(cstr(dateStamp) + " -" + vbTab + "Found "+Fromval(j) +" at " +Row +" The Value at "+Column +" is:"+Preval +" Replaced with "+ToValue + " at "+Column)
Else
'MsgBox (WHAT_TO_FIND & " not found")
End If
Next
Next
' oWS.Cells.Replace FromValue, ToValue
oWB.Save
oWB.Close
oExcelApp.Quit
End If
Next
logOutput.Close
Set logOutput = Nothing
Set objFsoLog = Nothing
Set WshShell = Nothing
oExcelApp.Quit
msgbox " Updated "&Count& " Files.",vbOkCancel,"Replaced Excel Files"
Const FromValue = "Y|LEARN MORE,30|LEARN MORE,Y|GET A QUOTE,Y|RECALL A QUOTE,C|LEARN MORE,50|GET A QUOTE,C|GET A QUOTE,C|RECALL A QUOTE"
fromval=Split(FromValue,",")
Const ToValue = "MobiRoot_TextObject"
dateStamp = Now()
Set WshShell = CreateObject("WScript.Shell")
sPath = WshShell.CurrentDirectory
Set fso = CreateObject("Scripting.FileSystemObject")
Set oExcelApp = CreateObject("Excel.Application")
Set objFsoLog = CreateObject("Scripting.FileSystemObject")
sLogFileName=sPath &"\LogFile-" &DatePart("d", Now) & "-" & DatePart("m", Now) & "-" & DatePart("yyyy", Now) &"-" & DatePart("n", Now) &".txt"
Set logOutput = objFsoLog.CreateTextFile(sLogFileName)
'Set logOutput = objFsoLog.OpenTextFile(sLogFileName, 8, True)
count=0
Dim WshShell, strCurDir
Set ObjFolder = fso.GetFolder(sPath)
Set ObjFiles = ObjFolder.Files
For Each ObjFile In ObjFiles
If LCase(Right(ObjFile.Name, 5)) = ".xlsx" Or LCase(Right(ObjFile.Name, 4)) = ".xls" Then
Count=Count+1
With oExcelApp
.Visible = False
.DisplayAlerts = False
Set oWB = .Workbooks.Open(ObjFile)
End With
Set oWS = oWB.Sheets(1)
logOutput.WriteLine(Replace(Replace(ObjFile,sPath,""),"\","-----"))
For j=0 to ubound(fromval)
For i=1 to 200
Row="G"&i
if oWS.Range(Row).Value = fromval(j) then
Column="F"&i
Preval=oWS.Range(Column).Value
oWS.Range(Column).Value=ToValue
logOutput.WriteLine(cstr(dateStamp) + " -" + vbTab + "Found "+Fromval(j) +" at " +Row +" The Value at "+Column +" is:"+Preval +" Replaced with "+ToValue + " at "+Column)
Else
'MsgBox (WHAT_TO_FIND & " not found")
End If
Next
Next
' oWS.Cells.Replace FromValue, ToValue
oWB.Save
oWB.Close
oExcelApp.Quit
End If
Next
logOutput.Close
Set logOutput = Nothing
Set objFsoLog = Nothing
Set WshShell = Nothing
oExcelApp.Quit
msgbox " Updated "&Count& " Files.",vbOkCancel,"Replaced Excel Files"
No comments:
Post a Comment