Hi.
Is there something like
FileCopy "this", "tothis"
that I can use to concatenate two files, similar to the
DOS command
copy "this" + "andthis" "tothis"
In addition to what John Nurick suggested, you could also use a batch file.
I'd recommend using the DOS append command instead of the DOS Copy command,
because the append command doesn't append a non-viewable character at the
end of the file like the Copy command does, which would probably have to be
removed later.
Create a batch file and execute it with the Shell Command method from VBA.
To do so, open the DOS command shell and type (or paste) the following:
Copy con AppendF.BAT
Echo Off
Type %1 %2 >> %3
Echo On
To copy the text from the console to the AppendF.BAT file, type:
<CTRL>Z
DOS will return the following message:
1 file(s) copied.
You'll need to know the directory where this file is stored so that DOS can
execute it even if it's not in the computer's environment path. For example
purposes, we'll store it in C:\Test. Create two text files and store them
in the same directory. We'll call these text files test1.txt and test2.txt.
Paste the following as a subroutine in a standard module (we'll call it
MyModule):
Public Sub ConcatFiles( )
On Error GoTo ErrHandler
Dim sFile As String
Dim sFileNext As String
Dim sFileConcat As String
Dim sCmd As String
Dim rtn As Double
sFile = "C:\Test\test1.txt"
sFileNext = "C:\Test\test2.txt"
sFileConcat = "C:\Test\test3.txt"
sCmd = "C:\Test\AppendF.BAT " & sFile & " " & sFileNext & " " &
sFileConcat
rtn = Shell(sCmd, vbHide)
If (rtn = 0) Then
MsgBox "There was an error processing the command."
End If
Exit Sub
ErrHandler:
MsgBox "Error in ConcatFiles( ) in MyModule." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear
End Sub
Now execute the sub to see how it works. The batch file you've written is
generic and will allow any two files to be concatenated into a third file.
All three file names (and their respective paths) are passed to the batch
file via the command-line arguments, each separated by a space.
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips.
(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)