Ich habe mein Macro mit dem ich TXT Files importiere, dies funktioniert soweit auch wunderbar, so lange ich eine Zelle auf dem 1. Tabellenblatt auswähle.
Sollte ich aber eine Zelle auf einem anderen Tabellenblatt auswählen, wird das TXT File trotzdem in das erste Tabellenblatt kopiert,
es wird zwar die richtige Zelle auf dem richtigen Blatt gewählt, aber der TXT Import erfolgt immer auf Blatt 1.
Hab schon alles Mögliche ausprobiert aber komme nicht auf die Lösung, was muss hier geändert werden?
Private Sub TXT_Import()
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
Dim rng As Range, TextLine As String, FilePath As String
Dim rw As Long, col As Long
Dim i As Long, j As Long, ary() As String, a As Variant
Dim txtfilesToOpen As Variant, txtfile As Variant
Set wb = Excel.ActiveWorkbook
Set fso = CreateObject("Scripting.FileSystemObject")
txtfilesToOpen = Application.GetOpenFilename _
(FileFilter:="Text Files (*.txt), *.txt", _
MultiSelect:=True, Title:="Text Files to Open")
MsgBox txtfile, vbOKOnly, "Gewählte Datei"
Set rng = Application.InputBox(Prompt:="Zelle zum einfügen wählen", Type:=8)
rng.Parent.Parent.Activate
rng.Parent.Activate
rw = rng.Row
col = rng.Column
Close #1
i = rw
Open txtfile For Input As #1
Do While Not EOF(1)
Line Input #1, TextLine
ary = Split(TextLine, vbTab)
j = col
For Each a In ary
Cells(i, j).Value = a
j = j + 1
Next a
i = i + 1
Loop
Close 1
Next txtfile
End Sub