Hallo zusammen, bin neu hier und weniger ahnung mit VBA.
Meine Problem ist:
Es gibt 1. und 2te Spalte, Script sollte im Zeile 2te Spalte überprüfen ob ist lerr WENN NICHT soll er auf nächste Zeile gehen, WENN Ja soll er aus Zeile Spalte 1. wert auslesen und extern speichern auf LW, mit bestimmte endung.
z.B.
Spalte:
-----------------------------------------
| 1te | 2te |
-----------------------------------------
| 23 | lerr |
-----------------------------------------
| 45 | leer |
-----------------------------------------
So habe ich angefangen:
Private Sub ExportList()
Dim OutDir As String
Dim DocCount As Long
Dim ColCount As Long
Dim ColumnName As String
Dim DescWert As String
Dim caption As String
Dim Doc As ItaDocument
Dim FileName As String
Dim Timestamp As String
Dim x As Long
Dim i As Long
Dim col As Long
Dim Row As Long
Dim strRow As String
Dim RowCount As Long
OutDir = "C:\rcs\evita\results"
Timestamp = Format$(Now,"yyyymmdd") & Format$(Now,"hhmmss")
caption = Replace(ResultWindow.Caption,"/","")
caption = Replace(caption," ", "_")
FileName = OutDir & "\" & caption & Timestamp & ".xls"
Dim printstring
Dim fn As Long
fn = FreeFile
Open FileName For Output As #fn
DocCount = ResultList.DocumentCount
ColCount = ResultList.ColumnCount
For x = 0 To ColCount -1
ColumnName = ResultList.ColumnName(x)
If x = 0 Then
printstring = ColumnName
Else
printstring = printstring & Chr(9) & ColumnName
End If
Next x
Print #fn, printstring
For x = 0 To DocCount-1
Set Doc = ResultList.Document(x)
For i = 0 To ColCount-1
DescWert = ResultList.CellValue(Doc,ResultList.ColumnName(i))
If i = 0 Then
printstring = DescWert
Else
printstring = printstring & Chr(9) & DescWert
End If
If ResultList.ColumnName(i) = "Sdg-Nr." Then
If ResultList.CellValue(Doc,ResultList.ColumnName(i)) = "" Then
<--- HIER SOLL ER SEIN IN SCHLEIFE --->
For Row = 0 To RowCount - 1
strRow = ""
Set Doc = ResultList.Document(Row)
For col = 0 To ColCount - 1
If col = 0 Then
strRow = ResultList.CellValue(Doc, ResultList.ColumnName(col))
Else
strRow = strRow & ";" & ResultList.CellValue(Doc, ResultList.ColumnName(col))
End If
Next col
Print #1, strRow
Next Row
End If
End If
Next i
Print #fn, printstring
Next x
Close #fn
End Sub
Ich bedanke mich.
PS. Es sollte wert auslesen und in gleiche wert gespeihert, also z.B. wert ist 23 er soll in 23.txt datei speichern.
Spalte 1 ist TL-Nr.
Spalte 2 ist Sdg-Nr.
Meine Problem ist:
Es gibt 1. und 2te Spalte, Script sollte im Zeile 2te Spalte überprüfen ob ist lerr WENN NICHT soll er auf nächste Zeile gehen, WENN Ja soll er aus Zeile Spalte 1. wert auslesen und extern speichern auf LW, mit bestimmte endung.
z.B.
Spalte:
-----------------------------------------
| 1te | 2te |
-----------------------------------------
| 23 | lerr |
-----------------------------------------
| 45 | leer |
-----------------------------------------
So habe ich angefangen:
Private Sub ExportList()
Dim OutDir As String
Dim DocCount As Long
Dim ColCount As Long
Dim ColumnName As String
Dim DescWert As String
Dim caption As String
Dim Doc As ItaDocument
Dim FileName As String
Dim Timestamp As String
Dim x As Long
Dim i As Long
Dim col As Long
Dim Row As Long
Dim strRow As String
Dim RowCount As Long
OutDir = "C:\rcs\evita\results"
Timestamp = Format$(Now,"yyyymmdd") & Format$(Now,"hhmmss")
caption = Replace(ResultWindow.Caption,"/","")
caption = Replace(caption," ", "_")
FileName = OutDir & "\" & caption & Timestamp & ".xls"
Dim printstring
Dim fn As Long
fn = FreeFile
Open FileName For Output As #fn
DocCount = ResultList.DocumentCount
ColCount = ResultList.ColumnCount
For x = 0 To ColCount -1
ColumnName = ResultList.ColumnName(x)
If x = 0 Then
printstring = ColumnName
Else
printstring = printstring & Chr(9) & ColumnName
End If
Next x
Print #fn, printstring
For x = 0 To DocCount-1
Set Doc = ResultList.Document(x)
For i = 0 To ColCount-1
DescWert = ResultList.CellValue(Doc,ResultList.ColumnName(i))
If i = 0 Then
printstring = DescWert
Else
printstring = printstring & Chr(9) & DescWert
End If
If ResultList.ColumnName(i) = "Sdg-Nr." Then
If ResultList.CellValue(Doc,ResultList.ColumnName(i)) = "" Then
<--- HIER SOLL ER SEIN IN SCHLEIFE --->
For Row = 0 To RowCount - 1
strRow = ""
Set Doc = ResultList.Document(Row)
For col = 0 To ColCount - 1
If col = 0 Then
strRow = ResultList.CellValue(Doc, ResultList.ColumnName(col))
Else
strRow = strRow & ";" & ResultList.CellValue(Doc, ResultList.ColumnName(col))
End If
Next col
Print #1, strRow
Next Row
End If
End If
Next i
Print #fn, printstring
Next x
Close #fn
End Sub
Ich bedanke mich.
PS. Es sollte wert auslesen und in gleiche wert gespeihert, also z.B. wert ist 23 er soll in 23.txt datei speichern.
Spalte 1 ist TL-Nr.
Spalte 2 ist Sdg-Nr.
Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von „suki“ ()