I’m working on a bit of code that I want to extract a small piece of text form a larger text file.
At the moment I can open and read the entire text file and also pin point a start and end marker of the text I want to extract.
What I’m having trouble doing is creating a variable text string which contains the text between the 2 markers.
What I have so far is
![]()
Function ExtractText() Dim sSearchText1 As String Dim sSearchText2 As String Dim sFileName As String Dim sFileText As String Dim strText As String Dim strStart As Integer Dim strEnd As Integer Const ForReading = 1 sSearchText1 = "--**Part1**" ' start point sSearchText2 = "--**Part2**" 'end point sFileName = "C:\Scripts\Script.sql" 'Create instance of FileSystemObject. Set objFSO = CreateObject("Scripting.FileSystemObject") Set objfile = objFSO.OpenTextFile(sFileName, ForReading) 'read entire contents of file, save to strText variable strText = objfile.ReadAll strStart = InStr(strText, sSearchText1) strEnd = InStr(strText, sSearchText2) End Function
Bookmarks