Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- For Each objFile In objFolder.Files
- Set tgtSheet = ThisWorkbook.Sheets.Add
- tgtSheet.Name = objFile.Name
- On Error Resume Next
- With tgtSheet.QueryTables.Add(Connection:="TEXT;" & objFile, Destination:=tgtSheet.Range("A1"))
- .TextFileParseType = xlDelimited
- .TextFileCommaDelimiter = True
- .Refresh
- End With
- On Error GoTo 0
- ' ------ Force data formatting onto columns
- lastRow = FindLastCell(tgtSheet).Row
- For i = 1 To UBound(titleArray)
- currCol = ColumnByTitle(tgtSheet, titleArray(i))
- With tgtSheet
- Set columnRange = .Range(.Cells(1, currCol), Cells(lastRow, currCol)).EntireColumn
- columnRange.NumberFormat = formatArray(i)
- End With
- Next i
- Next objFile
- With ThisWorkbook
- strPath = .Path
- strFile = .FullName
- strFileTemp = strPath & "DBtemp" & ".xlsb"
- .Worksheets(arrSheets).Copy
- End With
- For i = LBound(arrSheets) To UBound(arrSheets)
- If arrSheets(i) <> ActiveSheet.Name Then
- If strSQL = "" Then
- strSQL = "SELECT * FROM [" & arrSheets(i) & "$]"
- Else
- strSQL = strSQL & " UNION ALL SELECT * FROM [" & arrSheets(i) & "$]"
- End If
- End If
- Next i
- ' ------ set up connection string
- strCon = _
- "ODBC;" & _
- "DSN=Excel Files;" & _
- "DBQ=" & strFileTemp & ";" & _
- "DefaultDir=" & strPath & ";" & _
- "DriverId=790;" & _
- "MaxBufferSize=2048;" & _
- "PageTimeout=5"
- Set pc = ThisWorkbook.PivotCaches.Add(SourceType:=xlExternal)
- ' ------ test pivot table to play around with
- With pc
- .Connection = strCon
- .CommandType = xlCmdSql
- .CommandText = strSQL
- Set pt = .CreatePivotTable(TableDestination:=ActiveSheet.Range("A1"))
- pt.Name = "TestPivot"
- End With
Add Comment
Please, Sign In to add comment