I have a problem on this sentence:
Const LogFileName As String = "C:\demo.txt"
cos the file name should be selected through selection instead of hard code. How can i make it the selected directory instead of hard code the filename?
Sub RemoveLeadingTrailingSpaces()
Const LogFileName As String = "C:\demo.txt" 'Change the directory
Dim FileNum As Integer, tLine As String
Dim contents As String
Dim FileNumTemp As Integer, tempLine As String
contents = ""
FileNum = FreeFile ' next file number
FileNumTemp = FreeFile
Open LogFileName For Input Access Read Shared As FileNum
'Open LogFileName For Input As #FileNum ' open the file for reading
Do While Not EOF(FileNum)
Input #FileNum, tLine ' read a line from the text file
tLine = Trim(tLine)
'~~~~~~~~~~~~~~~~~~~~~comment on if else statement: ~~~~~~~~~~~~~~~~~~~~
'~~~~~~If the current data read is blank or is of zero length Then ~~~~~
'~~~~~~don 't append to the string ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~Else ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~append to the string for output ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~End ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If IsEmpty(tLine) Or tLine = CStr(0) Or tLine = "" Or tLine = " " Or tLine = Chr(10) Then
Else
contents = contents & tLine & Chr(10)
End If
Loop ' until the last line is read
contents = Trim(contents)
Close #FileNum ' close the file
Open LogFileName For Output As FileNumTemp
Print #FileNumTemp, contents;
Close #FileNumTemp
End Sub
Const LogFileName As String = "C:\demo.txt"
cos the file name should be selected through selection instead of hard code. How can i make it the selected directory instead of hard code the filename?
Sub RemoveLeadingTrailingSpaces()
Const LogFileName As String = "C:\demo.txt" 'Change the directory
Dim FileNum As Integer, tLine As String
Dim contents As String
Dim FileNumTemp As Integer, tempLine As String
contents = ""
FileNum = FreeFile ' next file number
FileNumTemp = FreeFile
Open LogFileName For Input Access Read Shared As FileNum
'Open LogFileName For Input As #FileNum ' open the file for reading
Do While Not EOF(FileNum)
Input #FileNum, tLine ' read a line from the text file
tLine = Trim(tLine)
'~~~~~~~~~~~~~~~~~~~~~comment on if else statement: ~~~~~~~~~~~~~~~~~~~~
'~~~~~~If the current data read is blank or is of zero length Then ~~~~~
'~~~~~~don 't append to the string ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~Else ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~append to the string for output ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~End ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If IsEmpty(tLine) Or tLine = CStr(0) Or tLine = "" Or tLine = " " Or tLine = Chr(10) Then
Else
contents = contents & tLine & Chr(10)
End If
Loop ' until the last line is read
contents = Trim(contents)
Close #FileNum ' close the file
Open LogFileName For Output As FileNumTemp
Print #FileNumTemp, contents;
Close #FileNumTemp
End Sub