AW: Parent-Child nicht vergessen
22.11.2023 21:53:00
Alwin Weisangler
Hallo Yal,
den Verdacht, dass es noch weiterer Tabellen incl. Verknüpfungen bedarf, hatte ich schon geäußert. Ich habe deswegen mich erst mal in Wartestellung begeben, da ich SAP nur vom Namen her kenne. Ich brauch da einfach konkrete Aussagen wie was zusammenhängt. Dann was zu programmieren um es in die erforderlichen Tabellen aufzudröseln ist vermutlich nicht so das Problem.
Vorhin habe ich mal noch den Import aller txt Dateien eines Verzeichnisses zusammengestellt. Den Code stell ich mal noch mit rein.
Option Explicit
Dim DateiName$
'hier Starten Verzeichnis auslesen
Sub TxtAusVerzeichnisImport()
Dim strPath$, strFile$, i&, arrTxtList()
If strPath = "" Then strPath = ShellVerzeichnisBrowser
If strPath > "" Then
strPath = IIf(Right(strPath, 1) = "\", strPath, strPath & "\")
strFile = Dir(strPath & "*.txt", vbNormal)
Do While strFile > ""
i = i + 1
ReDim Preserve arrTxtList(1 To i)
arrTxtList(i) = strPath & strFile
strFile = Dir
Loop
End If
For i = 1 To UBound(arrTxtList)
DateiName = arrTxtList(i)
TxtVerarbeiten
Next i
End Sub
'Daten aus der abzufragenden txt in die Excel holen
Sub TxtVerarbeiten()
Dim ZeileAusImport$, row_number&, i&, lz&, ls&
Dim objStream As Object
Dim ZeilenNummer
Set objStream = CreateObject("ADODB.Stream")
With objStream
.Charset = "utf-8"
.Open
If DateiName = "" Then Exit Sub
.LoadFromFile (DateiName)
.LineSeparator = 10
End With
With Tbl_ImpRohdaten
row_number = .Cells(Rows.Count, 1).End(xlUp).Row + 1
lz = .Cells(Rows.Count, 1).End(xlUp).Row
ls = .Cells(1, Columns.Count).End(xlToLeft).Column
Do Until objStream.EOS
ZeileAusImport = objStream.ReadText(-2)
If InStr(1, ZeileAusImport, "---") = 0 And InStr(1, ZeileAusImport, "Kostenart") = 0 Then
ZeilenNummer = Split(ZeileAusImport, "|")
For i = 1 To UBound(ZeilenNummer) - 1
If i = 1 Then
.Cells(row_number, i).NumberFormat = "@"
.Cells(row_number, i).Value = RTrim(ZeilenNummer(i))
Else
.Cells(row_number, i).Value = RTrim(ZeilenNummer(i))
End If
Next i
row_number = row_number + 1
End If
Loop
End With
Set objStream = Nothing
End Sub
Private Function ShellVerzeichnisBrowser(Optional ByVal defaultPath = "") As String
Dim objItem As Object, objShell As Object, objFolder As Object
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0&, "Bitte Verzeichnis anklicken", 0&, defaultPath)
If objFolder Is Nothing Then GoTo weiter
Set objItem = objFolder.Self
ShellVerzeichnisBrowser = objItem.Path
weiter:
Set objShell = Nothing
Set objFolder = Nothing
Set objItem = Nothing
End Function
Gruß Uwe