i need to copy first 10 rows from file1 and pasting in file2. i am writing the code as

Dim FNum1 As Integer
Dim FNum2 As Integer

Dim str As String

Open "C:\file1.txt" For Input As #FNum1
Open "C:\file2.txt" For output As #FNum2

Line Input #FNum1, str
Print #FNum2, str

Close #FNum1
Close #FNum2

but while opening the second file it gives an error as bad file name or number.

please help me out and let me know how to handle two files simultaneously.

I think you need to assign different number to each file number. You are opening each file using the same number, thus will have error. Try to use FreeFile. It will supply a number that is not being used or simply you assign different number like 1 and 2 respectively.


FNum1 = FreeFile
Open "C:\file1.txt" For Input As #FNum1

FNum2 = FreeFile
Open "C:\file1.txt" For Input As #FNum2


Hope this help.