| re: How to Import 2 files automatically? I think this is what you're looking for:
' fpath is the full address of the file to be read and
' dpath is the full address of the file to be written to
Public Function readTextFile(ByVal fpath As String, ByVal dpath As String)
On Error GoTo Err_readTextFile
Dim fhandle1 As Integer
Dim fhandle2 As Integer
Dim fline As String
' open the text file to be read
fhandle1 = FreeFile()
Open fpath For Input Access Read Lock Write As #fhandle1
'open the text file to be written to
fhandle2 = FreeFile
Open dpath For Output Access Write As #fhandle2
Do While Not EOF(fhandle1) ' loop until you reach the end of the file.
Line Input #fhandle1, fline ' read a line from the source file
fline = Trim(fline) ' cut off spaces
Print #fhandle2, fline ' write the line to the destination file
Loop
Close #fhandle1
Close #fhandle2
Exit_readTextFile:
Exit Function
Err_readTextFile:
Select Case Err
Case 0 '.insert Errors you wish to ignore here
Resume Next
Case Else '.All other errors will trap
Beep
MsgBox Err.Description, , "Error in Function Text File Handler.readTextFile"
Resume Exit_readTextFile
End Select
Resume 0 '.FOR TROUBLESHOOTING
End Function
|