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
Ich bin nicht sicher, aber Ich glaube, in Deinem Makro wird und bleibt die Quelldatei die aktive Datei. Irgendwann musst Du wieder zu Deiner Zieldatei zurückkehren. Versuche es doch mit folgender Ergänzung und Aenderung. „NameZieldatei.xls“ musst Du mit dem Namen Deiner Zieldatei ersetzen.
Ich habe den Fehler gefunden:
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