OS: Windows 10, 1903
Office: Office 2016
Powershell: 5.1
I have an excel file we'll call records.xlsm that gets automatically downloaded every day. I need to do things to that file and then send it on someplace else. I have created the necessary VBA code to automate this and that code resides in a .bas file we'll call cleanup.bas .
I'm attempting to find a way to use Powershell or some other canned Microsoft tool to automate running the vba code against the file. I haven't found a way (that I like) to do this yet with Powershell.
My goal is to use task scheduler to run a Powershell script to make the changes in records.xlsm using the code from cleanup.bas.
I don't mind if cleanup.bas has to be imported into records.xlsm but that process must also be automated too.
I assume it's possible. I'm asking to confirm / deny if it is or not. If possible, please tell me where I need to start looking documentation-wise.
I found code from here. I don't mind going that route, but it seems not so elegant. Practicality trumps Pretty though, so I'll use it if nothing else works.
$xl = New-Object -ComObject Excel.Application
$xl.Visible = $true
$xl.DisplayAlerts = $false
$workbook = $xl.Workbooks.Open("c:\temp\test.xls")
$xlmodule = $workbook.VBProject.VBComponents.Add(1)
$code = @"
sub cleanup()
'your code goes here
end sub
"@
$xlmodule.CodeModule.AddFromString($code)
Thanks for the time.