Hi everyone, I need help in order to import 12 files (.csv and .xlsx extensions) from one directory, into one master spreadsheet with multiple tabs. The issue is that the files are dumped onto my company server with time stamps in the file names and sheet names. I have attempted to truncate these stamps off by writing the below code but keep getting a compile error. I have also tried putting an asterisk or wild character in place of the time stamp but keep getting a compile error. Also, in the actual script, I replace the "K:" with the server UNC path. Thanks in advance!!!!
Sub OLSTest()
'
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;K:\OLS_Reports\New Horizon Data Files\AttPendingPutaway_022112.csv", _
Destination:=Range("$A$1"))
.Name = "AttPendingPutaway_022112"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "AttPendingPutawy"
Sheets("Sheet2").Select
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array( _
"OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;Data Source=K:\OLS_Reports\New Horizon Data Files\Att28DayEquipmentS" _
, _
"hipped_021712.xlsx;Mode=Share Deny Write;Extended Properties=""HDR=YES;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";" _
, _
"Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=37;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Je" _
, _
"t OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt D" _
, _
"atabase=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Je" _
, _
"t OLEDB:Support Complex Data=False;Jet OLEDB:Bypass UserInfo Validation=False" _
), Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdTable
.CommandText = Array("Att28DayEquipmentShipped_021712$")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = _
"K:\OLS_Reports\New Horizon Data Files\Att28DayEquipmentShipped_021712.xlsx"
.ListObject.DisplayName = "Table_Att28DayEquipmentShipped_021712"
.Refresh BackgroundQuery:=False
End With
Sheets("Sheet2").Select
Sheets("Sheet2").Name = "AttEquipmentShipped"
End Sub
Bookmarks