Open text file and convert containing text to string
Sub Test()
Dim fname As String
fname = ActiveWorkbook.path & "\Aggregated periods.txt"
strSql = OpenTextFileToString2(fname)
'replace word in string
strSql = Replace(strSql, "& core_id", core_id)
'Extract port of string embraced by "Aggregated_periods"
strSql = ExtractPartOfPath(strSql, "Aggregated_periods")
End Sub
Function OpenTextFileToString2(ByVal strFile As String) As String
Dim hFile As Long
hFile = FreeFile
Open strFile For Input As #hFile
OpenTextFileToString2 = Input$(LOF(hFile), hFile)
Close #hFile
End Function
Function ExtractPartOfPath(path As Variant, DivMark As String) As String
Dim first, second As Integer
first = InStr(path, DivMark)
second = InStr(first + 1, path, DivMark)
ExtractPartOfPath = Mid(path, first + Len(DivMark), second - first - Len(DivMark) - 1)
End Function