FileCopy Function / Open in Binary mode
Why don't you open both source and target file in binary mode?
Code:
Dim Data As String
Dim FileName As String
Dim BSize As Long
Dim fSz As Long
FileName = InputBox("Enter filename.", "Save")
If FileName <> "" Then
'Set the buffer size
BSize = 4096
Open App.Path & "\Controls.cont" For Binary Access Read As #1
Open App.Path & "\" & FileName For Binary Access Write As #2
fSz = LOF(1)
Do Until EOF(1)
' Don't read too much at the end.
If fSz - Loc(1) <= BSize Then BSize = fSz - Loc(1) + 1
' Read & write the data
Data = Space$(BSize)
Get #1, , Data
Put #2, , Data
DoEvents
Loop
Close #1
Close #2
MsgBox "File copy successful.", vbInformation + vbOKOnly, "Save"
Else
MsgBox "Please enter a valid fiilename.", vbExclamation + vbOKOnly, "Save"
End If
Yet, you also can use the VB build in FileCopy function as
Code:
Dim Source as string
dim Target as string
Source = "C:\Controls.cont"
Target = "C:\Target.txt"
FileCopy Source, Target