|
| 1 | +Public Sub concatenate_worksheets() |
| 2 | + Dim wk As Workbook |
| 3 | + Set wk = ThisWorkbook |
| 4 | + |
| 5 | + ' Open the current workbook |
| 6 | + Dim database As Worksheet |
| 7 | + Set database = wk.Worksheets("Base de données") |
| 8 | + |
| 9 | + ' Get the its current path |
| 10 | + Dim current_path As String |
| 11 | + current_path = wk.Path |
| 12 | + Dim file_name As String |
| 13 | + |
| 14 | + ' Open the workbook to analyze |
| 15 | + Dim opened_workbook As Workbook |
| 16 | + file_to_open = current_path & "\" & "google" & ".xlsx" |
| 17 | + Set opened_workbook = Application.Workbooks.Open(file_to_open) |
| 18 | + |
| 19 | + ' Ensure that we have all expected fields |
| 20 | + Dim opened_worbook_sheet As Worksheet |
| 21 | + Set opened_worbook_sheet = opened_workbook.Worksheets(1) |
| 22 | + opened_worbook_sheet.Activate |
| 23 | + |
| 24 | + ' Get the file header and check that |
| 25 | + ' we have the expected fields |
| 26 | + Dim opened_worbook_sheet_values As Range |
| 27 | + Set opened_worbook_sheet_values = opened_worbook_sheet.Range("A1:" & opened_worbook_sheet.Range("A1").End(xlToRight).End(xlDown).Address) |
| 28 | + |
| 29 | + ' Dim expected_columns As Object |
| 30 | + ' Set array_list = CreateObject("System.Collections.ArrayList") |
| 31 | + ' array_list.Add "nom" |
| 32 | + |
| 33 | + opened_worbook_sheet_values.Select |
| 34 | + |
| 35 | + ' For i = i To opened_worbook_sheet_values.Count |
| 36 | + |
| 37 | + ' Next i |
| 38 | + |
| 39 | + opened_worbook_sheet_values.Copy database.Range("C16") |
| 40 | + |
| 41 | + ' Since the copy also removes the |
| 42 | + ' initial styling, we have to |
| 43 | + ' reapply everything |
| 44 | + Dim copied_items As Range |
| 45 | + Set copied_items = database.Range("A10:F20") |
| 46 | + |
| 47 | + copied_items.Interior.Color = RGB(255, 255, 255) |
| 48 | + copied_items.Font.Name = "Source Sans Pro Light" |
| 49 | + copied_items.HorizontalAlignment = xlCenter |
| 50 | + opened_workbook.Close |
| 51 | +End Sub |
0 commit comments