Option Explicit
Private Function xlsGetLastRow(ByRef sheet As Object) As Long
Const xlCellTypeLastCell = 11
'Zur letzten initialisierten Zeile gehen
xlsGetLastRow = sheet.Cells.SpecialCells(xlCellTypeLastCell).Row
'Von dort zurücksuchen bis zur Letzten zeile mit Inhalt
Do While sheet.Application.WorksheetFunction.CountA(sheet.Rows(xlsGetLastRow)) = 0 And xlsGetLastRow > 1
xlsGetLastRow = xlsGetLastRow - 1
Loop
End Function
Private Function lastRowNr(ByRef ws As Worksheet)
lastRowNr = ws.UsedRange.SpecialCells(xlCellTypeLastCell).Row
End Function
Public Function xlsGetLastColumn(ByRef sheet As Object) As Long
Const xlCellTypeLastCell = 11
'Zur letzten initialisierten Zeile gehen
xlsGetLastColumn = sheet.Cells.SpecialCells(xlCellTypeLastCell).Column
'Von dort zurücksuchen bis zur Letzten zeile mit Inhalt
Do While sheet.Application.WorksheetFunction.CountA(sheet.Columns(xlsGetLastColumn)) = 0 And xlsGetLastColumn > 1
xlsGetLastColumn = xlsGetLastColumn - 1
Loop
End Function
'Private Function datum() As Date
' If Weekday(Date, vbMonday) = 1 Then
' datum = Date - 3
' Else
' datum = Date - 1
' End If
'End Function
Private Function datum() As Date
datum = ThisWorkbook.Worksheets("Makros").Range("A3")
End Function
Sub Report()
Dim sFile As String, sPath As String, iFree As Integer
Dim arrCSV, arrTmp, arrXLS(), i As Long, j As Integer, n As Long
Dim zFile As String
Dim source As Worksheet
Dim antwort As Integer
Set source = ActiveWorkbook.Worksheets("Makros")
sPath = "C:\Users\xxx\Desktop\"
sFile = Dir(sPath & "Liste Jerome.csv")
zFile = "Liste_xxx"
Application.ScreenUpdating = False
If Dir(sPath & "Liste xxx.csv") <> vbNullString Then
' Do While Len(sFile)
iFree = FreeFile
Open sPath & sFile For Input As iFree
arrCSV = Split(Input(LOF(iFree), iFree), vbCrLf)
Close iFree
For i = 0 To UBound(arrCSV)
arrTmp = Split(arrCSV(i), ";")
n = Application.Max(n, UBound(arrTmp))
Next
ReDim arrXLS(1 To UBound(arrCSV) + 1, 1 To n + 1)
For i = 0 To UBound(arrCSV)
arrTmp = Split(arrCSV(i), ";")
For j = 0 To UBound(arrTmp)
arrXLS(i + 1, j + 1) = arrTmp(j)
Next
Next
With Workbooks.Add
.Sheets(1).Cells(1, 1).Resize(UBound(arrXLS), UBound(arrXLS, 2)) = arrXLS
.SaveAs sPath & zFile
End With
'Loop
End If
Call Seite_erstellen
Call Kopie_Daten
Call Seite_einrichten
Call Zeilenumbruch
Call Spalten_alle_Worksheets
Call Rahmenlinien
Call Daten_speichern
Application.DisplayAlerts = False
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.DisplayAlerts = True
antwort = MsgBox("Wollen Sie die Daten löschen?", vbYesNo + vbQuestion)
'If antwort = vbYes Then
' Kill source.Range("B2") & source.Range("G5") & "*.xls"
' Kill source.Range("B2") & source.Range("G5") & "*.csv"
'Else
' Exit Sub
'End If
End Sub
Private Sub Seite_erstellen()
ActiveWorkbook.Worksheets("Tabelle1").Activate
Range(Cells(1, 1), Cells(1, 12)).Interior.ColorIndex = 6
Range(Cells(1, 1), Cells(1, 12)).Font.Bold = True
Range("G1").Value = "Priorität"
End Sub
Private Sub Seite_einrichten()
Dim source As Worksheet
ActiveWorkbook.Worksheets("Tabelle1").Activate
For Each source In Worksheets
With source.PageSetup
.Orientation = xlLandscape
.PaperSize = xlPaperA4
.PrintArea = "$A$1:$L$" & lastRowNr(source)
.FitToPagesWide = 1
.FitToPagesTall = 6
.Zoom = 38
.LeftMargin = Application.CentimetersToPoints(0.5)
.RightMargin = Application.CentimetersToPoints(0.5)
.HeaderMargin = Application.CentimetersToPoints(0.3)
.TopMargin = Application.CentimetersToPoints(0)
.FooterMargin = Application.CentimetersToPoints(0.3)
.BottomMargin = Application.CentimetersToPoints(0)
.CenterFooter = ""
.RightFooter = "Erstellt am " & Format(Date, "DD.MM.YYYY")
.LeftFooter = "Daten vom " & datum
End With
Next
End Sub
Private Sub Zeilenumbruch()
ActiveWorkbook.Worksheets("Tabelle1").Activate
Dim source As Worksheet
For Each source In Worksheets
source.Columns("A:AD").WrapText = True
Next
End Sub
Private Sub Spalten_alle_Worksheets()
ActiveWorkbook.Worksheets("Tabelle1").Activate
Dim source As Worksheet
For Each source In Worksheets
source.Columns("A:A").ColumnWidth = 19
source.Columns("B:B").ColumnWidth = 8.5
source.Columns("C:C").ColumnWidth = 99
source.Columns("D:D").ColumnWidth = 11
source.Columns("E:E").ColumnWidth = 8
source.Columns("F:F").ColumnWidth = 15.6
source.Columns("G:G").ColumnWidth = 9.3
source.Columns("H:H").ColumnWidth = 19.8
source.Columns("I:I").ColumnWidth = 10
source.Columns("J:J").ColumnWidth = 12.3
source.Columns("K:K").ColumnWidth = 22.3
source.Columns("L:L").ColumnWidth = 11.7
source.Rows("1:2000").AutoFit
Next
End Sub
Private Sub Rahmenlinien()
Dim source As Worksheet
Dim lastRow As Long
Dim lastCol As Long
Dim rowNr As Long
Dim rng As Range
ActiveWorkbook.Worksheets("Tabelle1").Activate
For Each source In Worksheets
lastRow = xlsGetLastRow(source)
lastCol = xlsGetLastColumn(source)
Set rng = source.Range("A1", source.Cells(lastRow, lastCol))
With rng.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 1
End With
With rng.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 1
End With
With rng.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 1
End With
With rng.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 1
End With
With rng.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 1
End With
With rng.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 1
End With
Next
End Sub
Sub Daten_speichern()
Dim ws As Worksheet
Dim SheetName As String
For Each ws In Worksheets
SheetName = ws.Name
Dim source As Worksheet
Dim sOrdner As String
Dim sblattname As String
Dim sFilename As String
Dim myDate As Date
Dim i As Integer
myDate = datum
'Werte aus source für Schleife
Set source = Workbooks("xxx.xlsm").Worksheets("Makros")
'Schleife für Ordner Erstellung & Speichern der Datei im richtigem Ordner
For i = lastRowNr(source) To 7 Step -1
'Ordner wo der Ordner sein soll
sOrdner = "L:\Global\xxx\" & Format(datum, "YYYY") & "\" & SheetName & "\"
sblattname = Format(datum, "YYYYMMDD") & "_" & SheetName
'Wenn Ordner nicht vorhanden, dann anlegen
If Dir(sOrdner, vbDirectory) <> "" Then
MkDir sOrdner
End If
sFilename = Application.GetSaveAsFilename(sOrdner & sblattname, "Micrsoft Excel-Dateien (*.xls),*.xls")
ws.Activate
ActiveSheet.Copy
ActiveWorkbook.SaveAs sFilename
ActiveWorkbook.Close False
Next i
Next ws
End Sub