Code Erklärung
04.11.2020 20:33:56
Jochen
ich würde mich über eine Erklärung des unten aufgeführten Codes freuen. Ich glaube der erste Teil fragt mich fragt welche Datei geöffnet werden soll und wo sie liegt. Der zweite Teil des Codes liest mir Daten aus anderen Dateien, jeweils 7 Tabellenblätter, ein. Die Tabellen haben 109 Zeilen aber es wird nur bis zur Zeile 60 gelesen. An welcher Stelle im Code kann ich das beeinflussen.
Erster Teil:
Public Sub ImportReports()
Dim intChoice As Integer
Dim strPath As String
Dim i As Integer
'allow the user to select multiple files
Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = True
Application.FileDialog(msoFileDialogOpen).Title = "Bitte wählen Sie die Berichte aus..."
Application.FileDialog(msoFileDialogOpen).Filters.Clear
Application.FileDialog(msoFileDialogOpen).Filters.Add "Excel 2010", "*.xlsm"
'make the file dialog visible to the user
intChoice = Application.FileDialog(msoFileDialogOpen).Show
'determine what choice the user made
If intChoice 0 Then
'get the file path selected by the user
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For i = 1 To Application.FileDialog(msoFileDialogOpen).SelectedItems.Count
strPath = Application.FileDialog(msoFileDialogOpen).SelectedItems(i)
'print the file path to sheet 1
'Cells(i + 1, 1) = strPath
Import strPath
Next i
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End If
End Sub
Zweiter Teil:Public Sub Import(strPath As String)
Dim wb As Workbook
Dim sht As Worksheet
Dim lastrow As Long
Dim activeWb As Workbook
Dim masterSht As Worksheet
activeWb = ThisWorkbook
masterSht = activeWb.Worksheets("Rohdaten")
lastrow = masterSht.UsedRange.Rows(masterSht.UsedRange.Rows.Count).Row
wb = Workbooks.Open(strPath)
For i = 1 To 7
sht = wb.Sheets(i)
Cells(lastrow + 1, 1) = strPath
Next i
Workbooks(strPath).Close
End Sub
Ich hoffe das ich mit einigermaßen verständlich ausgedrückt habe.
Danke im Voraus
Jochen
https://www.herber.de/bbs/user/141321.xlsm