By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,985 Members | 2,877 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,985 IT Pros & Developers. It's quick & easy.

How to Import 2 files automatically?

P: 3
Is there sample code to importing data from one text file then automatically importing data to another text file?
Aug 8 '06 #1
Share this Question
Share on Google+
1 Reply


MMcCarthy
Expert Mod 10K+
P: 14,534
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
Aug 9 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.