Hallo
Ich habe ein Makro mit dem ich daten importieren möchte.
Das aufrufen der Quelldatei(en) und Kopieren der Daten klappt.
Nur fügt es die Daten nicht in die Zieldaten ein. Das Makro steht in der Zieldatei.
Code:
Sub Daten_Import()
Application.EnableEvents = False
Dim strPath As String
strExt = "*.xls" 'Dateiextension ggf. anpassen
Dim strFile As String
Dim oFileDialog As FileDialog
Set oFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
With oFileDialog
.Title = „Wählen Sie bitte den gewünschten Ordner aus!“
.ButtonName = „Übernehmen“
.InitialFileName = „T:\NM_Public\HFCP\10 SCANPET\01_Daten Konsolidierung\01_Eingang“
If .Show = True Then
strPath = .SelectedItems(1) & „“
Else: Exit Sub
End If
End With
'strPath = " Cells(1, 1).Value & Cells(1, 2).Value & Cells(1, 3).Value & Cells(1, 4).Value"
'strPath = UserForm1.TextBox1.Text & „“
If strPath = "" Then
Exit Sub
Else
strFile = Dir(strPath & strExt)
Do While Len(strFile) > 0
Workbooks.Open Filename:=strPath & strFile
'UserForm.showmodal = False
'QUELLDATEI
ActiveWorkbook.Sheets(„BYB“).Cells(2, 1).Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Copy
'ZIELDATEI
FreieZeile = ThisWorkbook.Sheets("alle erfassten").Cells(Rows.Count, 20).End(xlUp).Row + 1
ThisWorkbook.Sheets(„alle erfassten“).Cells(FreieZeile, 1).Value = ActiveSheet.Paste
'Call keine_MAC
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
Application.EnableEvents = True
'...
'ActiveWorkbook.Close
strFile = Dir() ' nächste Datei
Loop
End If
'ActiveWorkbook.Save
'Application.Quit
End Sub
Gruss
Walti