commit
a0a4cab0cf
|
@ -0,0 +1,35 @@
|
|||
# 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."
|
Loading…
Reference in New Issue