Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Sub process()
- Dim oldSheet As Worksheet
- Dim newSheet As Worksheet
- Set oldSheet = Worksheets("Data")
- Set newSheet = Worksheets.Add()
- Application.DisplayAlerts = False
- oldSheet.Delete
- Application.DisplayAlerts = True
- newSheet.Name = "Data"
- Dim fso As New Scripting.fileSystemObject
- Dim folder As folder
- Dim mappa As String
- mappa = Worksheets("Parameters").Range("folder").Value
- Set folder = fso.GetFolder(mappa)
- Dim F As Scripting.File
- Dim first As Boolean
- first = True
- For Each F In folder.Files
- If first Then
- 'Debug.Print F.Name 'View>ImmediateWindow
- FileImport F.Path, True
- first = False
- Else
- FileImport F.Path, False
- End If
- Next F
- 'FileImport "C:\Users\Kokusz\Documents\ExcelVBA\SharedFiles\Excel\MonthlyData\resolveit_exp_2016-01.xlsx", True
- End Sub
- Sub FileImport(filePath As String, Optional copyHeader As Boolean = True)
- Application.DisplayAlerts = False
- 'open file
- 'ChDir "C:\Users\Kokusz\Documents\ExcelVBA\SharedFiles\Excel\MonthlyData"
- Dim Wb As Workbook
- Set Wb = Workbooks.Open(Filename:=filePath)
- 'selecting all data
- Dim Ws As Worksheet
- Set Ws = Wb.ActiveSheet
- Wb.Activate 'csak active sheeten lehet kijelölni
- Dim R As Range
- Set R = Ws.UsedRange
- If Not copyHeader Then
- Set R = R.Resize(R.Rows.Count - 1)
- Set R = R.Offset(1)
- End If
- R.Select
- Selection.Copy
- Dim lastRow As Integer
- Windows("Report.xlsm").Activate
- lastRow = ActiveSheet.UsedRange.Rows.Count
- If Not lastRow = 1 Then
- ActiveSheet.Cells(lastRow + 1, 1).Select
- Else
- Range("A1").Select
- End If
- ActiveSheet.Paste
- Selection.PasteSpecial Paste:=xlPasteColumnWidths, _
- Operation:=xlNone, skipBlanks:=False
- 'Workbooks("resolveit_exp_2016-01.xlsx").Close False
- 'Windows("resolveit_exp_2016-01.xlsx").Activate
- 'ActiveWindow.Close False
- Wb.Close SaveChanges:=False
- Application.DisplayAlerts = True
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement