The attached has comments in the code to guide you.
The idea is that you can have your sheet like this:
2018-07-25_010204.jpg
Where there are blank cells in columns A and B, their value is assumed to be the same as the first non-blank cell above it.
The same does NOT apply to column C and D.
The code should only open and close files when a file name (effectively) changes as it works its way down the list.
Do test it thoroughly.
This is the code but it's in the file:
Sub Search_Replace_TextFile()
Const ForReading = 1
Const ForWriting = 2
Dim objFSO As Object
Dim objFile As Object
Dim fName As String, CurrentfName As String, g As String, FolderName As String, FilName As String
Dim i As Long, LR As Long
Dim strText As String
With ActiveSheet
'Assign a few things:
LR = .Cells(Rows.Count, "C").End(xlUp).Row 'uses column C to determine extent of data to process.
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Make an initial check that A2:B2 contains a valid folder name and file name and that that file exists, otherwise abort:
fName = .Range("A" & 2).Value & "\" & .Range("B" & 2).Value
If objFSO.fileexists(fName) Then
For i = 2 To LR
'this bit handles blanks in column A and B and makesthe assumption if there's a blank it means it's the same as the first non-blank above it.
'.Range("A" & i).Select 'debug line
g = .Range("A" & i).Value
If Len(Application.Trim(g)) > 0 Then FolderName = g
g = .Range("B" & i).Value
If Len(Application.Trim(g)) > 0 Then FilName = g
fName = FolderName & "\" & FilName
If fName <> CurrentfName Then 'it's a different file so
'write/update existing file:
If Len(CurrentfName) > 0 Then '(but check that there is an open file first)
Set objFile = objFSO.OpenTextFile(CurrentfName, ForWriting)
objFile.WriteLine strText
objFile.Close
End If
'open new file and read and close:
Set objFile = objFSO.OpenTextFile(fName, ForReading)
strText = objFile.ReadAll
objFile.Close
'update current file name:
CurrentfName = fName
End If
'Case insensitive:
strText = Replace(strText, Range("C" & i), Range("D" & i), Compare:=vbTextCompare)
'Case sensitive:
'strText = Replace(strText, Range("C" & i), Range("D" & i), Compare:=vbBinaryCompare)
Next i
'update and close the last file:
Set objFile = objFSO.OpenTextFile(CurrentfName, ForWriting)
objFile.WriteLine strText
objFile.Close
Else
MsgBox "File in A2:B2 doesn't exist. Aborting"
End If
End With
Set objFile = Nothing
Set objFSO = Nothing
End Sub