I'm building an import functionality for a program that enables a user to import Excel data, Text files (with any delimiter) and .csv files (with any delimiter).
I have set up the Opendialog and a way to determine and limit the data source, but now I want to inspect the first line (or couple of lines of text) in the .csv or .txt file to determine which character repeats regularly across the first 5 lines (most probably the delimiter) and open this file already split into columns by that delimiter.
`Dim delimiter as string
'Determine delimiter...
'For .txt files:
Workbooks.OpenText Filename:=FileName:=FullPath, DataType:=xlDelimited, Other:=True, OtherChar:=delimiter
'For .csv files:
Workbooks.Open FileName:=FullPath, Format:=6, Delimiter:=delimiter`
I would like to determine the most probable delimiter based on the character that repeats the most across the first few lines of text in the file.