justme1122
New Member
- Joined
- Mar 6, 2011
- Messages
- 47
Hi guys,
So I have this code that mass imports a directory into a single worksheet, the code works fine:
I also pulled this line of code from the macro recorder that will hopefully make it so CSV files will format correctly:
Could some one please advise on where I could place this line of code in my script to make it work.
Thank you for your time
Scott
So I have this code that mass imports a directory into a single worksheet, the code works fine:
Code:
Sub CombineFiles()
Dim path As String
Dim FileName As String
Dim LastCell As Range
Dim Wkb As Workbook
Dim WS As Worksheet
Dim ThisWB As String
ThisWB = ThisWorkbook.Name
Application.EnableEvents = False
Application.ScreenUpdating = False
path = GetDirectory
FileName = Dir(path & "\*.xls", vbNormal)
Do Until FileName = ""
If FileName <> ThisWB Then
Set Wkb = Workbooks.Open(FileName:=path & "\" & FileName)
For Each WS In Wkb.Worksheets
Set LastCell = WS.Cells.SpecialCells(xlCellTypeLastCell)
If LastCell.Value = "" And LastCell.Address = Range("$A$1").Address Then
Else
WS.Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
End If
Next WS
Wkb.Close False
End If
FileName = Dir()
Loop
Application.EnableEvents = True
Application.ScreenUpdating = True
Set Wkb = Nothing
Set LastCell = Nothing
End Sub
I also pulled this line of code from the macro recorder that will hopefully make it so CSV files will format correctly:
Code:
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
1)
Could some one please advise on where I could place this line of code in my script to make it work.
Thank you for your time
Scott