ich habe einen Code, der soweit gut funktioniert, bis auf die letzte Zeile. Im Code wird zuerst ein Teil eines Tabellenblatts in eine andere Excel Datei exportiert. Im 2. Schritt soll ein anderes Tabellenblatt komplett exportiert werden in eine neue separate Datei. Das funktioniert auch, aber ich würde gerne den Speicherort anpassen. Und zwar auf Basis des Speicherorts der Datei in die die ersten Daten kopiert werden. Im Grunde habe ich gedacht, dass in der letzten Zeile anstatt wbkTF.SaveAs wksTF.Parent.Path einfach wbkTF.SaveAs wbimport.Parent.Path stehen müsste. Das funktioniert aber leider nicht.
Ich hoffe ich konnte es gut beschrieben, wo mein Problem ist und Danke schon mal vorab. :-)
LG
Martin
Sub Export()
Dim lngRow As Long, rng As Range, wksTF As Worksheet, wbkTF As Workbook
Dim i As Long
Dim importdatei As Variant
Dim wbimport As Workbook
With Sheets(2)
For lngRow = 2 To 200000
If .Cells(lngRow, 18) > 0 Then
If rng Is Nothing Then
Set rng = .Range(.Cells(lngRow, 1), .Cells(lngRow, 46))
Else
Set rng = Union(rng, .Range(.Cells(lngRow, 1), .Cells(lngRow, 46)))
End If
End If
Next
End With
If Not rng Is Nothing Then
importdatei = Application.GetOpenFilename(filefilter:="Microsoft Exel-Dateien(*.xlsx),*. _
xlsx", Title:="Datei auswählen")
If importdatei = False Then Exit Sub
Set wbimport = Workbooks.Open(importdatei)
With wbimport.Worksheets(1)
rng.Copy
.Cells(.Cells(.Rows.Count, 1).End(xlUp).Row + 1, 1).PasteSpecial xlValues
Application.CutCopyMode = False
wbimport.Save
wbimport.Close
End With
End If
Set rng = Nothing
Set wksTF = ActiveWorkbook.Worksheets(7)
wksTF.Copy
Set wbkTF = ActiveWorkbook
wbkTF.SaveAs wksTF.Parent.Path & "\" & "TF-" & ThisWorkbook.Sheets(4).Range("C1") & ".xlsx"
End Sub