It works like a charm on some Windows PC, but failed sometimes when running on those PC with heavier loadings
Would encountering the following issues
- Rejected by the callee
- "Open" MethodNotFound
- When Application.Workbooks.count = 1, those issues would be reproduced
- When Application.Workbooks.count = 0, those issue would disappear
Sample Code
$excel = New-Object -ComObject Excel.Application
$excel.Visible = $true
$excel.DisplayAlerts = $false
#When the count of $excel.workbooks is 0, $excel.workbooks is ready.
#When the count is greater than 0, $excel.workbooks is not initialized yet
while ($excel.workbooks.count -gt 0) {
Start-Sleep -milliseconds 100
Write-Debug "Initializing..."
}
$workbook = $excel.workbooks.Open($file)