Suggestions please... the following code runs successfully as far as creating daily spreadsheets for the year, but the vba codes or macros fail to copy to the new workbooks. In addition to this macro, there are two others that are not showing up in the new files. Thanks in advance for your insight.
Option Explicit
Sub Create_Multiple_Workbooks()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.StatusBar = False
'
Dim i As Long
Dim wb As Workbook
Dim fec1 As Date, fec2 As Date
Dim l1 As Workbook, h1 As Worksheet
Dim ruta As String, mes As String, ruta2 As String, arch As String
Set l1 = ThisWorkbook
Set h1 = l1.Sheets("Ops-Fleetwatch-GFI Comparison") 'name of template sheet
'
ruta = l1.Path & "\"
fec1 = DateSerial(2021, 7, 1) 'YYYY, M, D'
fec2 = DateSerial(2022,6, 30) 'YYYY, M, D'
For i = fec1 To fec2
Application.StatusBar = "Creating file : " & i
mes = Format(i, "MMM")
If Dir(ruta & mes & "\") = "" Then
MkDir (ruta & mes)
End If
ruta2 = ruta & mes & "\"
arch = "Operations-Fleetwatch-GFI Daily Vehicle Log " & Format(i, "MM-DD-YYYY")
ActiveWorkbook.Sheets.Copy
[b4] = Format(i, "DDDD, mm/dd/yyyy 04:00:00")
[e4] = Format((i + 1), "DDDD, mm/dd/yyyy 03:59:59")
Set wb = ActiveWorkbook
Range("E4").NumberFormat = "dd-mm-yyy"
wb.SaveAs Filename:=ruta2 & arch & ".xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled
wb.Close False
Next
Application.StatusBar = False
MsgBox "End"
End Sub
Option Explicit
Sub Create_Multiple_Workbooks()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.StatusBar = False
'
Dim i As Long
Dim wb As Workbook
Dim fec1 As Date, fec2 As Date
Dim l1 As Workbook, h1 As Worksheet
Dim ruta As String, mes As String, ruta2 As String, arch As String
Set l1 = ThisWorkbook
Set h1 = l1.Sheets("Ops-Fleetwatch-GFI Comparison") 'name of template sheet
'
ruta = l1.Path & "\"
fec1 = DateSerial(2021, 7, 1) 'YYYY, M, D'
fec2 = DateSerial(2022,6, 30) 'YYYY, M, D'
For i = fec1 To fec2
Application.StatusBar = "Creating file : " & i
mes = Format(i, "MMM")
If Dir(ruta & mes & "\") = "" Then
MkDir (ruta & mes)
End If
ruta2 = ruta & mes & "\"
arch = "Operations-Fleetwatch-GFI Daily Vehicle Log " & Format(i, "MM-DD-YYYY")
ActiveWorkbook.Sheets.Copy
[b4] = Format(i, "DDDD, mm/dd/yyyy 04:00:00")
[e4] = Format((i + 1), "DDDD, mm/dd/yyyy 03:59:59")
Set wb = ActiveWorkbook
Range("E4").NumberFormat = "dd-mm-yyy"
wb.SaveAs Filename:=ruta2 & arch & ".xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled
wb.Close False
Next
Application.StatusBar = False
MsgBox "End"
End Sub