opener/opener.ps1

36 lines
911 B
PowerShell

# Define the path to the text file containing the list of Excel file paths
$fileListPath = "C:\Path\To\filelist.txt"
# Read all lines (file paths) from the text file
$filePaths = Get-Content -Path $fileListPath
# Create an Excel application object
$excel = New-Object -ComObject Excel.Application
$excel.Visible = $true
# Open each file in Excel
foreach ($file in $filePaths) {
if (Test-Path $file) {
Write-Host "Opening $file"
$workbook = $excel.Workbooks.Open($file)
} else {
Write-Host "File not found: $file"
}
}
# Wait for 2 minutes (120 seconds)
Start-Sleep -Seconds 120
# Close all workbooks without saving
$excel.Workbooks.Close($false)
# Quit Excel
$excel.Quit()
# Release the COM object
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel) | Out-Null
[GC]::Collect()
[GC]::WaitForPendingFinalizers()
Write-Host "Excel closed after 2 minutes."