You can write a VBA macro (reuse what you have already written) and call it from Excel in a VBS script that it started by Windows Scheduler when you want.
My BAT file
::********************************************************************
::* Generate-Excel-File.bat
::********************************************************************
@echo ON
SETLOCAL ENABLEDELAYEDEXPANSION
C:\windows\syswow64\cscript.exe LoadExcel.vbs
My VBS file
'*****************************************************************************
'* LoadExcel.vbs
'*****************************************************************************
' Create a WshShell to get the current directory
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
' Create an Excel instance
Dim oExcel
Dim oWorkBook
Set oExcel = CreateObject("Excel.Application")
' Disable Excel UI elements
oExcel.DisplayAlerts = False
oExcel.AskToUpdateLinks = False
oExcel.AlertBeforeOverwriting = False
oExcel.FeatureInstall = msoFeatureInstallNone
' Tell Excel what the current working directory is
' (otherwise it can't find the files)
Dim strSaveDefaultPath
Dim strPath
strSaveDefaultPath = oExcel.DefaultFilePath
strPath = WshShell.CurrentDirectory
oExcel.DefaultFilePath = strPath
' Open the Workbook specified on the command-line
Set oWorkBook = oExcel.Workbooks.Open(strPath & "\US.TRACKING-FILE.NEW.xlsm")
' Build the macro name with the full path to the workbook
on error resume next
' Run the calculation macro
oExcel.Run "LoadCSV"
if err.number <> 0 Then
' Error occurred - just close it down.
End If
err.clear
on error goto 0
'oWorkBook.Save
'oExcel.DefaultFilePath = strSaveDefaultPath
' Clean up and shut down
Set oWorkBook = Nothing
' Don’t Quit() Excel if there are other Excel instances
' running, Quit() will
' shut those down also
if oExcel.Workbooks.Count = 0 Then
oExcel.Quit
End If
Set oExcel = Nothing
Set WshShell = Nothing
I hope that can help you to solve your problem.
In this example, I load a CSV file in Excel but if you want, you can run a SQL command in VBA and fill what you want using pure Excel macros.