View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Ulrich Möller Ulrich Möller is offline
external usenet poster
 
Posts: 7
Default Merge several fixed width text files into one

Am 14.06.2017 um 00:38 schrieb Ulrich Möller:
Public Sub MergeFiles(ByVal InFile As String, ByVal OutFile As String)
Const COPYCMD As String = "for %f in ({0}) do type ""%f"" {1}"

Dim strCopyCommand As String
Dim dblRetVal As Double

strCopyCommand = Replace(COPYCMD, "{0}", InFile)
strCopyCommand = Replace(strCopyCommand, "{1}", OutFile)

SyncShell "cmd.exe /c " & strCopyCommand, vbNormalFocus
End Sub


Sorry for the mixed data types, here the corrected version:

Public Sub MergeFiles(ByVal InFile As String, ByVal OutFile As String)
Const COPYCMD As String = "for %f in ({0}) do type ""%f"" {1}"

Dim strCopyCommand As String
Dim lngRetVal As Long

strCopyCommand = Replace(COPYCMD, "{0}", InFile)
strCopyCommand = Replace(strCopyCommand, "{1}", OutFile)

lngRetVal = SyncShell("cmd.exe /c " & strCopyCommand, vbNormalFocus)
End Sub

Public Function SyncShell(ByVal Cmd As String, ByVal WindowStyle As
VbAppWinStyle) As Long
SyncShell = VBA.CreateObject("WScript.Shell").Run(Cmd, WindowStyle,
True)
End Function

Ulrich