I'm trying to add "#" in each cell in the first column since Row7 until the cell is blank. And I have several files in one folder which needs to repeat. Is it possible to do this by VBA? It always shown, there's something wrong with the code. Many thanks for help.
Sub LoopAllFilesInAFolder()
'Loop through all files in a folder
Dim fileName As Variant
fileName = Dir("C:\Users)
While fileName <> ""
'Insert the actions to be performed on each file
Dim last As Long
Dim i As Long
'Find the last row with values in Column A
last = .Cells(.Rows.Count, 1).End(xlUp).Row
'Loop from the 7th row to the last row.
For i = 7 To last
'Assign the value
Cells(i, 1).Value = "#" & Cells(i, 1).Value
Next i
'This example will print the file name to the immediate window
Debug.Print fileName
'Set the fileName to the next file
fileName = Dir
Wend
End Sub
Please, try the next adapted code:
Sub LoopAllFilesInAFolder()
Dim folderName As String, fileName As String, wb As Workbook
Dim ws As Worksheet, last As Long, i As Long, arr
folderName = "C:\Users\Lin.Yu\Desktop\NewFolder\" 'take care to the ending backslash
fileName = Dir(folderName & "*.xlsx")
While fileName <> ""
Set wb = Workbooks.Open(folderName & fileName)
Set ws = wb.Sheets(1) 'use here the appropriate sheet, if not the first one
With ws
'Find the last row with values in Column A
last = .cells(.rows.count, 1).End(xlUp).row
arr = .Range("A1:A" & last).value 'put the column in an array to make the code faster
'Loop from the 7th array row to the last row and process.
For i = 7 To UBound(arr)
arr(i, 1) = "#" & arr(i, 1)
Next i
.Range("A1:A" & last).value = arr 'drop the processed array content
End With
wb.Close True 'save and close the processed workbook
'Set the fileName to the next file
fileName = Dir
Wend
End Sub
Edited:
Please, test the next compact variant, using Evaluate instead of iteration:
Sub LoopAllFilesInAFolder()
Dim folderName As String, fileName As String, wb As Workbook
Dim ws As Worksheet, last As Long, i As Long, rng As Range
folderName = ThisWorkbook.path & "\" ' "C:\Users\Lin.Yu\Desktop\NewFolder\"
fileName = Dir(folderName & "*.xlsx")
While fileName <> ""
Set wb = Workbooks.Open(folderName & fileName)
Set ws = wb.Sheets(1) 'use here the appropriate sheet, if not the first one
With ws
'Find the last row with values in Column A
last = .cells(.rows.count, 1).End(xlUp).row
Set rng = .Range("A7:A" & last)
rng.value = Evaluate("""#""&" & rng.Address)
End With
wb.Close True 'save and close the processed workbook
'Set the fileName to the next file
fileName = Dir
Wend
End Sub
You seem to be showing two things:
The code to find all files you want to process.
The code you want to apply on the workbook in those files.
What you didn't to, is create a VBA workbook, based on the files you have found. This is explained in this URL.
Tried FaneDuru's code, it worked for the first time. After that, It was either shown as above which only has # or not responding.
Related
I am hoping someone could help me with my code. I am pretty sure I am close to solving the issue but I just can't figure out why certain things are happening when the code runs.
My goal:
Open up a directory that contains a main document
Open that document and grab the last row position
Open the Workbooks in the second directory containing multiple files with multiple sheets in each workbook.
Open each Workbook in the client(Second) directory and check if cell A33 on each worksheet contains info.
Grab the last row of the client file for the copy range
Copy the data starting at A33 to U(Lastrow) and paste it to the blank row in the main document
Update the new last row position in the main document
Close the document and proceed to the next sheet, if there is no sheet the proceed to the next workbook and go through that workbooks sheets and repeat.
To begin - all of the code runs fine up until the second directory Do While Loop.
The first issue I am having is that my code to assign the value of the last row to a variable is returning an incorrect number.
'Get the last row of the client worksheet currently opened
clientLR = wsClient.Cells(wsClient.Rows.Count, "A").End(xlUp).Row 'Returns incorrect last row number (7)**
The second issue is that my do while function loops before the for each function can get the next file.
'Loop again to the next file in client directory to be opened
Loop 'Can't call next file without looping to do while statement again which opens same document**
'Call the next file in the client directory to be opened
Next file
Here is the full code view.
Sub sourceFile2()
Call loopThroughFiles("Z:\Filepath\")
End Sub
Sub loopThroughFiles(ByVal path As String)
Dim fso As Object
Set fso = CreateObject("scripting.FileSystemObject")
Dim folder As Object
Set folder = fso.GetFolder(path)
Dim file As Object
Dim wsOverall As Worksheet
Dim wbOverall As Workbook
Dim overallLR As Long
Dim overallFilepath As String
Dim overallFile As String
Dim wbClient As Workbook
Dim clientLR As Long
Dim wsClient As Worksheet
Dim cellValue As String
'Suppress alerts for clipboard prompt bypass + screen updating
Application.DisplayAlerts = False
Application.ScreenUpdating = False
'declare overall file path and file type
overallFilepath = "Z:\Filepath\"
overallFile = Dir(overallFilepath)
'loop through overall file directory
Do While overallFile <> ""
'Open file in overall directory
Set wbOverall = Workbooks.Open(overallFilepath & overallFile)
Set wsOverall = wbOverall.Sheets("Overall")
'Find First Blank Row in overall document
overallLR = Cells(Rows.Count, 1).End(xlUp).Offset(1).Row
'Debug.Print overallFile
overallFile = Dir()
'Loop until no files left in directory
Loop
'For each file in the client folder
For Each file In folder.Files
'Loop through the files in client directory until no file is left
Do While file.Name <> ""
DoEvents
'Declare and open the workbook for each file in directory
Set wbClient = Application.Workbooks.Open(path & file.Name)
'For each worksheet in the Client workbook
For Each wsClient In wbClient.Worksheets
'Grab the value of Cell A33 in client workbook to compare
cellValue = Range("A33").Value
'Compare the value of cell A33 in client workbook to make sure it contains data
If cellValue <> "" Then
'Get the last row of the client worksheet currently opened
clientLR = wsClient.Cells(wsClient.Rows.Count, "A").End(xlUp).Row 'Returns incorrect last row number (7)**
'Copy the range all the way to the last row in client worksheet and paste it to the overall documents first blank row
wsClient.Range("A33:U" & clientLR).Copy
wsOverall.Range("A" & overallLR).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
'Update new overall documents last row position
overallLR = Cells(Rows.Count, 1).End(xlUp).Offset(1).Row
End If
'Close the current opened workbook
wbClient.Close
'Call the next worksheet in the client file to be copied to the overall document again
Next wsClient
'Loop again to the next file in client directory to be opened
Loop 'Can't call next file without looping to do while statement again which opens same document**
'Call the next file in the client directory to be opened
Next file
'remainder code
'Turn alerts back on
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Try this out (untested, but should be close)
Sub sourceFile2()
Call loopThroughFiles("Z:\Filepath\")
End Sub
Sub loopThroughFiles(ByVal path As String)
Const OVERALL_PATH As String = "Z:\Filepath\"
Dim folder As Object, file
Dim wsOverall As Worksheet, wbOverall As Workbook
Dim overallLR As Long, overallFilepath As String
Dim overallFile As String, wbClient As Workbook, xlFiles As Collection
Dim clientLR As Long, wsClient As Worksheet, cellValue As String
overallFile = Dir(OVERALL_PATH & "*.xls*", vbNormal) 'find the "overall" Excel file
If Len(overallFile) = 0 Then
MsgBox "No overall file found"
Exit Sub
End If
Set xlFiles = AllFiles(path, "*.xls*") 'collect all Excel files in `path`
If xlFiles.Count = 0 Then
MsgBox "No files to process", vbExclamation
Exit Sub
End If
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Set wbOverall = Workbooks.Open(OVERALL_PATH & overallFile)
Set wsOverall = wbOverall.Sheets("Overall")
overallLR = SheetLastRow(wsOverall) + 1 'next empty row
For Each file In xlFiles
Set wbClient = Application.Workbooks.Open(file)
For Each wsClient In wbClient.Worksheets
cellValue = wsClient.Range("A33").Value '<<< specify worksheet here!
If Len(cellValue) > 0 Then
clientLR = SheetLastRow(wsClient)
If clientLR >= 33 Then
With wsClient.Range("A33:U" & clientLR)
.Copy
wsOverall.Range("A" & overallLR).PasteSpecial _
Paste:=xlPasteValuesAndNumberFormats
overallLR = overallLR + .Rows.Count
End With
End If
End If
Next wsClient
wbClient.Close savechanges:=False
Next file
'rest of code...
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
'Return all matching files in `folder` where file name matches `pattern`
Function AllFiles(ByVal folder As String, pattern As String) As Collection
Dim f
Set AllFiles = New Collection
If Right(folder, 1) <> "\" Then folder = folder & "\"
f = Dir(folder & pattern, vbNormal)
Do While Len(f) > 0
AllFiles.Add folder & f
f = Dir()
Loop
End Function
'find the last used row in a sheet
Function SheetLastRow(ws As Worksheet) As Long
Dim f As Range
Set f = ws.Cells.Find(what:="*", After:=ws.Cells(1), LookAt:=xlPart, _
LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
If Not f Is Nothing Then
SheetLastRow = f.Row 'otherwise 0
Debug.Print "'" & f.Parent.Name & "' in '" & _
f.Parent.Parent.Name & "' = " & f.Address
End If
End Function
Good day all,
I have managed to scrape this code together, which works, BUT I need all the data on only 1 sheet, pasted on the first blank cell in column A. I have noticed Copy.Range, but it battling to integrate it into this code.
Sub ConsolidateWorkbooks()
Dim FolderPath As String
Dim Filename As String
Dim Sheet As Worksheet
Application.ScreenUpdating = False
FolderPath = "P:\FG\03_OtD_Enabling\Enabling\Teams\Enabling_RPA\Other Automations\Excel Merge Several Files\Data\"
Filename = Dir(FolderPath & "*.xls*")
Do While Filename <> ""
Workbooks.Open Filename:=FolderPath & Filename, ReadOnly:=True
For Each thisSheet In ActiveWorkbook.Worksheets
thisSheet.Copy After:=ThisWorkbook.Worksheets(1)
Next thisSheet
Workbooks(Filename).Close
Filename = Dir()
Loop
Application.ScreenUpdating = True
End Sub
Try the next code, please. It copies the sheets content starting from the second row (I only presume that the first row keeps column headers). If you need to copy everything, the code will be even simpler, The code should be fast enough, using an array to copy the range (without formatting):
Sub ConsolidateWorkbooks()
Dim FolderPath As String, Filename As String, sh As Worksheet, ShMaster As Worksheet
Dim wbSource As Workbook, lastER As Long, arr
'adding a new sheet on ThisWorkbook (after the last existing one)
Set ShMaster = ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Worksheets(ThisWorkbook.Sheets.count))
Application.ScreenUpdating = False
FolderPath = "P:\FG\03_OtD_Enabling\Enabling\Teams\Enabling_RPA\Other Automations\Excel Merge Several Files\Data\"
Filename = Dir(FolderPath & "*.xls*")
Do While Filename <> ""
'set the workbook to be open:
Set wbSource = Workbooks.Open(Filename:=FolderPath & Filename, ReadOnly:=True)
For Each sh In ActiveWorkbook.Worksheets 'iterate between its sheets
lastER = ShMaster.Range("A" & rows.count).End(xlUp).row 'last empty row
'put the sheet range in an array:
arr = sh.Range(sh.UsedRange.cells(1, 1).Offset(1, 0), _
sh.cells(sh.UsedRange.rows.count - sh.UsedRange.row + 1, _
sh.UsedRange.Columns.count)).Value
'drop the array content at once:
ShMaster.Range("A" & lastER).Resize(UBound(arr), UBound(arr, 2)).Value = arr
Next sh
wbSource.Close 'close the workbook
Filename = Dir() 'find the next workbook in the folder
Loop
Application.ScreenUpdating = True
End Sub
I've been trying to scavange together a macro which will merge several .CSV files.
However, the data I need in said file (GPS data) is located in different rows of column A. I therefor need it to search for part of a string, in this case there are a few strings related to GPS, but I only need GPS latitud and longitude (which will always be found one after another).
Any help is appreciated! The code might look a bit.. like shit, ive been trying to mess with it to make it work together!
Sub MergeAllWorkbooks()
Dim SummarySheet As Worksheet
Dim FolderPath As String
Dim directory As Object
Dim NRow As Long
Dim FileName As String
Dim WorkBk As Workbook
Dim SourceRange As Range
Dim DestRange As Range
Dim S_Lat, S_Long, D_Lat, D_Long As Range
Dim i As Integer
Dim icount As Integer
Dim icount2 As Integer
Application.ScreenUpdating = False
Application.DisplayAlerts = False
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
If .Show = -1 Then '-1 = yes or true
FolderPath = .SelectedItems(1) & "\"
Else
MsgBox "FilePath not selected!", , "Path selecter"
Exit Sub
End If
End With
' Create a new workbook and set a variable to the first sheet.
Set SummarySheet = Workbooks.Add(xlWBATWorksheet).Worksheets(1)
' NRow keeps track of where to insert new rows in the destination workbook.
NRow = 2
' Call Dir the first time, pointing it to all .csv files in the folder path.
FileName = dir(FolderPath & "*.csv")
SummarySheet.Range("A1") = "Filnamn"
SummarySheet.Range("B1") = "Latitud"
SummarySheet.Range("C1") = "Longitud"
' Loop until Dir returns an empty string.
Do While FileName <> ""
' Open a workbook in the folder
Set WorkBk = Workbooks.Open(FolderPath & "\" & FileName)
' Set the cell in column A to be the file name.
SummarySheet.Range("A" & NRow).Value = FileName
' Set the source range to be A9 through C9.
' Modify this range for your workbooks.
' It can span multiple rows.
For i = 1 To 200
If InStr(1, LCase(Range("A" & i)), "GPS Latitude") <> 0 Then 'If GPS appears in the string then
icount = i
icount2 = icount + 1
Set S_Lat = WorkBk.Worksheets(1).Range("A" & icount) ' Set the S_Lat variable
Set S_Long = WorkBk.Worksheets(1).Range("A" & icount2) ' Set the S_Long variable
Exit For
End If
Next i
' Set the destination range to start at column B and
' be the same size as the source range.
' SummarySheet.Range("B" & NRow).Value = S_Lat.Value ***** Didnt work? ******
' SummarySheet.Range("C" & NRow).Value = S_Long.Value ***** Didnt work? ******
Set D_Lat = SummarySheet.Range("B" & NRow)
Set D_Long = SummarySheet.Range("C" & NRow)
' Copy over the values from the source to the destination.
D_Lat.Value = S_Lat.Value
D_Long.Value = S_Long.Value
' Increase NRow so that we know where to copy data next.
NRow = NRow + D_Lat.Rows.Count
' Close the source workbook without saving changes.
WorkBk.Close savechanges:=False
' Use Dir to get the next file name.
FileName = dir()
Loop
' Call AutoFit on the destination sheet so that all
' data is readable.
' SummarySheet.Columns.AutoFit
End Sub
This simple code is not giving you a complete working macro, it will Look for "Latitude" in column A and when found it will transfer the cel.value, and the cel.value below it, to two rows side-by-side in column B and column C on the same worksheet. You will need to wrap it inside your Workbooks.Open loop, modify the Range in the source worksheet to include a last row, include a last row for your new workbook's worksheet and add it to the code inside the If statement. Try to work this into your code and when you encounter problems, you can return to SO and ask a specific question concerning your macro. The macro was tested with actual longitudes and latitudes, in column A, an placed in columns B and C side-by-side.
Dim lRow As Long
lRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
For Each cel In Range("A1:A38")
If InStr(1, cel.Value, "Latitude") Then
x = x + 1
Cells(x, 2).Value = cel.Value
Cells(x, 3).Value = cel.Offset(1).Value
End If
Next cel
So I want to automate a lot of manual work of copy/paste with the help of a Macro. The macro should read all files from folder one by one, copy the content from that source file range "I9:J172" and paste it on the destination file (where the macro is of course) on the column first blank row.
Application.ScreenUpdating = False
'For Each Item In franquicia
' OPEN THE SOURCE EXCEL WORKBOOK IN "READ ONLY MODE".
Set src = Workbooks.Open("C:\folder\inventory.xlsb", True, True)
' GET THE TOTAL ROWS FROM THE SOURCE WORKBOOK.
Dim iTotalRows As Integer
iTotalRows = src.Worksheets("INV").Range("I9:J" & Cells(Rows.Count, "J").End(xlUp).Row).Rows.Count
' FIND FIRST BLANK CELL
Dim LastRow As Long
LastRow = Worksheets("Hoja1").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
' COPY DATA FROM SOURCE (CLOSE WORKGROUP) TO THE DESTINATION WORKBOOK.
Dim iCnt As Integer ' COUNTER.
For iCnt = 1 To iTotalRows
Worksheets("Hoja1").Range("A" & LastRow & ":B" & iCnt).Value = src.Worksheets("INV").Range("I9:J172" & iCnt).Value
Next iCnt
' CLOSE THE SOURCE FILE.
src.Close False ' FALSE - DON'T SAVE THE SOURCE FILE.
Set src = Nothing
'Next Item
I want to solve first this last row problem and then do an array and the loop to read all the files one by one.
Thank you!
The following code does what you've described, and the animated gif demonstrates with 3 test files (with test data in the columns you mentioned). The first part of the gif shows the contents of 2 of the test files, and then runs the macro, stepping through it, showing the result on a "combined" sheet. Click on the gif to see better detail. Note that each test file's data must be on a "data" sheet. You can modify, of course.
Option Explicit
Dim theDir As String, alreadyThere As Boolean, wk As Workbook
Dim sh As Worksheet, comboSh As Worksheet, comboR As Range
Dim r As Range, s As String, numFiles As Integer
Const ext = ".xlsx"
Sub CombineFiles()
Set comboSh = getSheet(ThisWorkbook, "Combined", True)
theDir = ThisWorkbook.Path
s = Dir(theDir & "\*" & ext)
Set comboR = comboSh.Range("A1")
While s <> ""
ThisWorkbook.Activate
If comboR <> "" Then Set comboR = comboR.Offset(0, 2)
comboR.Activate
Set wk = Workbooks.Open(theDir & "\" & s)
Set sh = getSheet(wk, "data", False)
Set r = sh.Range("I9:J72")
'Set r = sh.Range(r, r.End(xlToRight))
'Set r = sh.Range(r, r.End(xlDown))
r.Copy
comboSh.Paste
Application.DisplayAlerts = False
wk.Close False
Application.DisplayAlerts = True
s = Dir()
numFiles = numFiles + 1
Wend
MsgBox ("done")
End Sub
Function getSheet(wk As Workbook, shName As String, makeIfAbsent As Boolean) As Worksheet
alreadyThere = False
For Each sh In wk.Worksheets
If sh.Name = shName Then
alreadyThere = True
Set getSheet = sh
End If
Next
If Not alreadyThere Then
If makeIfAbsent Then
Set getSheet = wk.Sheets.Add
getSheet.Name = shName
Else
MsgBox shName & " sheet not found -- ending"
End
End If
End If
End Function
I may be arriving to the party too late. It seems like you got the solution you were after. For future reference, try the AddIn below. This will do all kinds of copy/paste/merge tasks.
https://www.rondebruin.nl/win/addins/rdbmerge.htm
I have some csv files in one folder. They all contain 3 specific columns. The number of total columns and the order may vary.
I want to concatenate all 3 columns with an underscore and write them in a single column in the worksheet that is running the code.
Here is what I have so far:
Option Explicit
Sub test()
Dim i As Long
Dim LastRow As Long
Dim Columns()
Columns = Array("Column1", "Column2", "Column3")
'Find Columns by Name
For i = 0 To 2
Columns(i) = Rows(1).Find(What:=Columns(i), LookIn:=xlValues, LookAt:=xlWhole, _
MatchCase:=False, SearchFormat:=False).Column
Next i
'Debug.Print Columns(0)
'Debug.Print Columns(1)
'Debug.Print Columns(2)
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To LastRow
Cells(i, 1) = Cells(i, Columns(0)) & "_" & Cells(i, Columns(1)) & "_" & Cells(i, Columns(2))
Next i
End Sub
As you can see, this does what I want, but only for the active sheet.
I actually want to loop through all csv files in the same folder as the active sheet and write the results in the first sheet, first column of the sheet running the code (which is not a csv itself obviously).
How can I do this?
thanks!
This is a code that will loop through a folder
Sub Button1_Click()
Dim MyFile As String, Str As String, MyDir As String, Wb As Workbook
Set Wb = ThisWorkbook
'change the address to suite
MyDir = "C:\WorkBookLoop\"
MyFile = Dir(MyDir & "*.xls") 'change file extension
ChDir MyDir
Application.ScreenUpdating = 0
Application.DisplayAlerts = 0
Do While MyFile <> ""
Workbooks.Open (MyFile)
'do something here
MyFile = Dir()
Loop
End Sub
It depends how you are naming the worksheets you create from the CSV files. You could add all the worksheets to a collection and use a For...Each loop to execute the entire search and concatenate procedure within that loop. Note that you'd have to explicitly define the first sheet name as this won't change through successive loops:
Option Explicit
Sub test()
Dim i As Long
Dim LastRow As Long
Dim Columns()
Dim frontSheet as Worksheet
Dim wSheets as New Collection
Dim ws as Worksheet
Set frontSheet = Sheets("name of front sheet")
'Add all your CSV sheets to wSheets using the .Add() method.
For Each ws in wSheets
Columns = Array("Column1", "Column2", "Column3")
'Find Columns by Name
For i = 0 To 2
Columns(i) = ws.Rows(1).Find(What:=Columns(i), LookIn:=xlValues, LookAt:=xlWhole, _
MatchCase:=False, SearchFormat:=False).Column
Next i
'Debug.Print Columns(0)
'Debug.Print Columns(1)
'Debug.Print Columns(2)
LastRow = ws.Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To LastRow
frontsheet.Cells(i, 1) = ws.Cells(i, Columns(0)) & "_" & ws.Cells(i, Columns(1)) & "_" & ws.Cells(i, Columns(2))
Next i
Next ws
End Sub
It's often slow and labourious to open CSV files in excel but VBA can read them as text files using a TextStream. Furthermore, file scripting objects let you work with files and directories directly. Something like this might be a better approach if you don't need to keep the files in a worksheet afterwards:
Sub SearchFoldersForCSV()
Dim fso As Object
Dim fld As Object
Dim file As Object
Dim ts As Object
Dim strPath As String
Dim lineNumber As Integer
Dim lineArray() As String
Dim cols() As Integer
Dim i As Integer
Dim frontSheet As Worksheet
Dim frontSheetRow As Integer
Dim concatString As String
Set frontSheet = Sheets("name of front sheet")
frontSheetRow = 1
strPath = "C:\where-im-searching\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(strPath)
For Each file In fld.Files
If (Right(file.Name, 3) = "csv") Then
Debug.Print file.Name
Set ts = file.OpenAsTextStream()
lineNumber = 0
Do While Not ts.AtEndOfStream
lineNumber = lineNumber + 1
lineArray = Split(ts.ReadLine, ",")
If (lineNumber = 1) Then
'We are at the first line of the .CSV so
'find index in lineArray of columns of interest
'Add extra ElseIf as required
For i = LBound(lineArray) To UBound(lineArray)
If lineArray(i) = "Column 1" Then
cols(1) = i
ElseIf lineArray(i) = "Column 2" Then
cols(2) = i
ElseIf lineArray(i) = "Column 3" Then
cols(3) = i
End If
Next i
Else
'Read and store the column of interest from this
'row by reading the lineArray indices found above.
concatString = ""
For i = LBound(cols) To UBound(cols)
concatString = concatString & lineArray(i) & "_"
Next i
concatString = Left(concatString, Len(concatString) - 1)
frontSheet.Cells(frontSheetRow, 1).Value = concatString
frontSheetRow = frontSheetRow + 1
End If
Loop
ts.Close
End If
Next file
End Sub
You can find more information on FileSystemObject and TextStream here.