Ich habe ein VB-Makro, welches mir aus einer Exceltabelle mit Daten ein
SQL-Skript erstellt. Das ist die Schleife, die die komplette Tabelle durcharbeitet.
Code:
For iWks = 1 To ActiveWorkbook.Worksheets.Count
Open sPath & "Inhalt-Kostenstellen.sql" For Output As #1
Set rng = ActiveWorkbook.Worksheets(iWks).Range("A1").CurrentRegion
Print #1, "delete from kostenstellen where mandant > 0;"
For iRow = 2 To rng.Rows.Count
sTxt = sTxt & "INSERT INTO Kostenstellen(Mandant,Abteilung,Kostenstelle,Bezeichnung,CompanyID,Gesellschaft,Title) VALUES ("
For iCol = 1 To rng.Columns.Count - 1
If iCol = rng.Columns.Count - 1 Then
sTxt = sTxt & "'" & ActiveWorkbook.Worksheets(iWks).Cells(iRow, iCol).Value & "'); "
Else
If iCol = 1 Then
sTxt = sTxt & ActiveWorkbook.Worksheets(iWks).Cells(iRow, iCol).Value & ", "
Else
sTxt = sTxt & "'" & ActiveWorkbook.Worksheets(iWks).Cells(iRow, iCol).Value & "', "
End If
End If
Next iCol
Print #1, Left(sTxt, Len(sTxt) - 1)
sTxt = ""
Next iRow
Close #1
Next iWks
Dieser Teil geht jede Zeile und Spalte durch.