Excelgoodies logo +44 (0)20 3769 3689

LEARN THIS HANDS ON

Excel VBA Programming

GMT . Live Online FILLING FAST
View all upcoming batches
Merge text files using VBA

Merge text files using VBA

 

Merge text files using VBA

The below code merges around 50 ascii files into one It uses File System Object and you need to add a reference of Microsoft Scripting Runtime

 

Sub Append_Text_Files()

Dim F1 As FileSystemObject
Dim F2 As FileSystemObject

Dim oTS As TextStream
Dim oTS1 As TextStream

Dim vTemp

Set F1 = New FileSystemObject
Set F2 = New FileSystemObject

For i1 = 1 To 50

Set oTS = F1.OpenTextFile(“c:\Sheet” ; i1 ; “.txt”, ForReading)
vTemp = oTS.ReadAll

Set oTS1 = F1.OpenTextFile(“c:\CombinedTemp.txt”,
ForAppending, True)
oTS1.Write (vTemp)

Next i1

End Sub

Explore comprehensive Excel VBA Macro Course here and, automate your routine Excel Reports, tasks and processes.

 

Happy Excelling
Team Excelgoodies

VBA & Python

New

Next Batches Now Live

Power BIPower BI
SQLSQL
Power AppsPower Apps
Power AutomatePower Automate
Microsoft FabricMicrosoft Fabrics
AzureAzure Data Engineering
Explore Dates & Reserve Your Spot → Reserve Your Spot →