Ich habe mit hilfe von Mike einen VB Code geschrieben der mir eine Excel-Datei erstellt und mit einer Anzahl von Sheets füllt.
Ich möchte aber die Sheets nach einer Vorlage erstellen.
Kann mir jemand zeigen wie das in VBA geht.
Gruß
Public Sub Create_File_and_Sheets(Monat As String, Days As Integer)
Dim i As Double
Dim c As Integer
Dim x As Integer
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Add
For i = 1 To Days
c = Worksheets.Count
x = (i) + 1
If x > Days Then
Worksheets.Add After:=Worksheets(c)
ActiveSheet.Name = (i)
xlBook.SaveAs App.Path & "\" & Monat & ".xls"
xlBook.Saved = True
Set xlBook = Nothing
xlApp.Quit
Exit Sub
End If
Worksheets.Add After:=Worksheets(c)
'Sheets.Add Type:="C:\Users\" & Environ("USERNAME") & "\Desktop\Excel\" & "Prototyp1. _
xlt"
ActiveSheet.Name = (i) & "-" & x
Worksheets.Add After:=Worksheets(c)
ActiveSheet.Name = (i)
Next i
End Sub
Ich erzeuge eine Mappe mit der Anzahl der Tag und Nächte. Die Sheets werden gleich mit den Zahlen benannt. Also 1, 1-2,2,2-3 usw.
Sub DreiEinfügen()
Dim Zelle As Range
On Error GoTo ErrExit
GetMoreSpeed
For Each Zelle In ThisWorkbook.Sheets("Liste").Range("A1:A" & ThisWorkbook.Sheets("Liste"). _
Cells(Rows.Count, 1).End(xlUp).Row)
ThisWorkbook.Sheets("Muster").Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count) _
With ActiveSheet
.Name = Zelle.Value
.Cells(1, 1) = Zelle.Value
.Cells(1, 2).Value = Zelle.Offset(0, 1).Value
End With
Next
ErrExit:
GetMoreSpeed 0
End Sub
Sub GetMoreSpeed(Optional ByVal Modus As Integer = 1)
Static lngCalc As Long
With Application
If Modus = 1 Then
lngCalc = .Calculation
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
.Calculation = -4135
.Cursor = xlWait
Else
.ScreenUpdating = True
.EnableEvents = True
.DisplayAlerts = True
.Calculation = IIf(lngCalc 0, lngCalc, -4105)
.Cursor = xlDefault
End If
End With
End Sub
https://www.herber.de/bbs/user/88020.xls
Die erweiterte Suchfunktion hilft dir, gezielt die besten Antworten zu finden
Suche nach den besten AntwortenEntdecke unsere meistgeklickten Beiträge in der Google Suche
Top 100 Threads jetzt ansehen