I am creating a VBA macro that will create an identical workbook for every day of the year. It works great with one exception... the workbook names are created and saved successfully, but there are 2 cells that need to update in each of the workbooks. This is a no brainer I'm sure, but I'm missing the parameter placement that will call out the cell that needs changed. That should automatically update the 2nd cell based on a formula in the workbook. Following is the code and an image of the cells that need to change
----------------
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, 2)
fec2 = DateSerial(2022, 6, 30)
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
Set wb = ActiveWorkbook
wb.SaveAs Filename:=ruta2 & arch & ".xlsx", _
FileFormat:=xlOpenXMLWorkbook
wb.Close False
Next
Application.StatusBar = False
MsgBox "End"
End Sub
B1 needs to increase by 1 day and my existing formula will automatically update the value in cell E4.
Thanks in advance.
----------------
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, 2)
fec2 = DateSerial(2022, 6, 30)
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
Set wb = ActiveWorkbook
wb.SaveAs Filename:=ruta2 & arch & ".xlsx", _
FileFormat:=xlOpenXMLWorkbook
wb.Close False
Next
Application.StatusBar = False
MsgBox "End"
End Sub
B1 needs to increase by 1 day and my existing formula will automatically update the value in cell E4.
Thanks in advance.