VBA and Windows Scheduler

AdriLand

New Member
Joined
Jan 13, 2025
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Good day.

I have a functional Excel knowledge; however, is very new to task automations. Essentially, I want to automate the following process using Windows Scheduler and Excel Macros:
- Open Excel
- Open PERSONAL.XLSB
- Open latest file in the specified path
- Run Macro called OutstandingInvoiceReport
- Save and upload changes

I have done the following:
- Created a new module in the VBA editor in Excel, which contains the following:

Sub RunOutstandingInvoiceReport()
Dim xlApp As Object
Dim xlBook As Object
Dim personalBook As Object
Dim folderPath As String
Dim newestFile As String
Dim newestDate As Date
Dim fileDate As Date
Dim file As Object
Dim fso As Object

folderPath = "C:\Users\AdriL\OneDrive - FC\SEP\2024 2025\Outstanding Reports - Daily"
Set fso = CreateObject("Scripting.FileSystemObject")
newestDate = DateSerial(1900, 1, 1)

For Each file In fso.GetFolder(folderPath).Files
fileDate = file.DateLastModified
If fileDate > newestDate Then
newestDate = fileDate
newestFile = file.Path
End If
Next file

If newestFile <> "" Then
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False ' Keep Excel hidden

' Open PERSONAL.XLSB
Set personalBook = xlApp.Workbooks.Open(xlApp.Application.StartupPath & "\PERSONAL.XLSB")

' Open the newest file
Set xlBook = xlApp.Workbooks.Open(newestFile)

' Run the macro
xlApp.Run "OutstandingInvoiceReport"

' Save and close the newest file
xlBook.Save
xlBook.Close

' Close PERSONAL.XLSB
personalBook.Close SaveChanges:=False

' Quit Excel
xlApp.Quit

Set xlBook = Nothing
Set personalBook = Nothing
Set xlApp = Nothing
Else
MsgBox "No files found in the specified folder."
End If

Set fso = Nothing
End Sub

I then created a new file in Notepad, pasted the same script into it and saved it as Macro For OutstandingInvoiceReport.vbs

When I try to run it, I receive the following warning:
Line 2
Char 15
Error Expected end of statement
Code 800A0401
Source Microsoft BBScript compilation error


Can someone please tell me where I am going wrong? Any advice will be greatly appreciated. I use Microsoft / Excel 365 and Windows 11, if it is makes a difference.

Thank you!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Maybe this is the reason?
RunOutstandingInvoiceReport() <<name of your sub that you posted
OutstandingInvoiceReport << Call that you are trying to make?
 
Upvote 0

Forum statistics

Threads
1,225,487
Messages
6,185,272
Members
453,285
Latest member
Wullay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top