My script works for the most part, however I just think it's really messy and could be cleaned up better. I replaced the actual string values with generic ones as they contained some data pertaining to my organization. Basically I need it to go through a txt files (students.txt) and remove the strings and delete the empty lines. Also at the end of the file there is a string that shows how many rows were affected (i.e. 95 rows affected). I need to remove this as well. The number isn't always the same or I would just set it to remove the specific string. Any ideas would be greatly appreciated.
Dim st1, st2, st3, st4, st5, st7, st8, st9, st10, st11, st12, st13, st14, st15, st16, st17, st18, st19, st20, st21
st1 = "This is string 1"
st2 = "This is string 2"
st3 = "This is string 3"
st4 = "This is string 4"
st5 = "This is string 5"
st6 = "This is string 6"
st7 = "This is string 7"
st8 = "This is string 8"
st9 = "This is string 9"
st10 = "This is string 10"
st11 = "This is string 11"
st12 = "This is string 12"
st13 = "This is string 13"
st14 = "This is string 14"
st15 = "This is string 15"
st16 = "This is string 16"
st17 = "This is string 17"
st18 = "This is string 18"
st19 = "This is string 19"
st20 = "This is string 20"
st21 = "This is string 21"
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st1, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st2, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st3, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st4, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st5, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st6, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st7, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st8, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st9, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st10, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st11, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st12, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st13, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st14, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st15, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st16, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st17, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st18, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st19, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st20, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, st21, "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "-", "")
Set objFile = objFSO.OpenTextFile("C:\Scripts\sql\students.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
'----------------------------------------------------------------------------------------------
'Deletes Blank Lines
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\SQL\students.txt", ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.Readline
strLine = Trim(strLine)
If Len(strLine) > 0 Then
strNewContents = strNewContents & strLine & vbCrLf
End If
Loop
objFile.Close
Set objFile = objFSO.OpenTextFile("C:\Scripts\SQL\students.txt", ForWriting)
objFile.Write strNewContents
objFile.Close