Works flawlessly in excel need it to be working on your compiled exe file too
This line an error too -Input #intFNumber, DrawDate, P1, sP2, sP3, Draw, dDate
Sub ReadTextFile
Application.ScreenUpdating = False
'Read data from a text file
Dim DrawDate As String
Dim dDate As Date
Dim Draw As String
Dim P1 As String
Dim sP2 As String
Dim sP3 As String
Dim intSize As Integer
Dim Sheet1 As Worksheet
Set Sht = ThisWorkbook.Worksheets("Import")
ActiveSheet.Range("A1").Select
Dim sFName As String
Dim intFNumber As Integer
Dim lRow As Long
Sheets(“Import”).Protect Password:=“Test123”, UserInterFaceOnly:=True
Sheets(“HistoryD”).Protect Password:=“Test123”, UserInterFaceOnly:=True
ChDir "C:\Program Files\Test"
Dim fpath: fpath = Application.GetOpenFilename(“Text Files (.txt),.txt”)
If fpath = False Then Exit Sub
With ActiveSheet.QueryTables.Add(Connection:=“TEXT;” & fpath, Destination:=Range(“A1”))
End With
'The full path of the text file that will be opened
sFName = ThisWorkbook.Path & "\Import1.txt"
'Get an unused file number
intFNumber = FreeFile
On Error Resume Next
'Prepare text file for reading
Open sFName For Input As #intFNumber
'Check if the text file was found
If Err.Number <> 0 Then
MsgBox "Text file not found!", vbCritical, "Error!"
Exit Sub
End If
On Error GoTo 0
'Clearing the sheet
Sht.Activate
Sht.Cells.Clear
lRow = 1
'Loop until the end of file
Do While Not EOF(intFNumber)
'Read data from the text file
Input #intFNumber, DrawDate, P1, sP2, sP3, Draw, dDate
'Input #intFNumber, (DrawDate, “yy/mm/dd”), sP1, sP2, sP3, Draw
’Write selected data to the worksheet
With Sht
.Cells(lRow, 1) = DrawDate
.Cells(lRow, 2) = P1
.Cells(lRow, 3) = sP2
.Cells(lRow, 4) = sP3
.Cells(lRow, 6) = Draw
End With
'Address next row of worksheet
lRow = lRow + 1
Loop
'Close the text file
Close #intFNumber
'Fitting column width
Sht.Cells.EntireColumn.AutoFit
'Just showing where the output data are
Sht.Activate
Range("A2").Select
'Inform the user about the process
MsgBox "Values from file '" & sFName & "' were imported to sheet '" & Sht.Name & "'!", , "GOLFER65 TEST APP"
Sheets("HistoryD").Activate
Application.ScreenUpdating = True
ThisWorkbook.Save
Application.Quit
End Sub