locked
Powershell: Excel is blocking execution – how to get an error/exception? RRS feed

  • Question

  • Hi,

    I have a PowerShell script that uses Excel via (New-Object -ComObject Excel.Application).

    Sometimes the script is blocked by excel – it is not continuing with the execution of the scripts.

    This is very annoying as the script is automatically triggered so I get to know it only after hours.

    Unfortunately I don’t see the problem that Excel has then …

    Can I get Excel to trough an Exception so that the script can log it, handle the problem and go on?

    Last time I realized that the problem was a missing network share … or a missing Excel Cell …

    No matter what I simple want excel to stop and don’t block the script execution.

    Is there a way?

    
    Sunday, October 5, 2014 10:58 PM

Answers

  • It's of no help but just for your information MS don't actually support unattended automation of Office Apps for just this reason.

    If you're running this as a scheduled task you could try setting a timeout value and aborting if it over-runs then re-attempt the process.

    • Marked as answer by Bill_Stewart Thursday, October 16, 2014 9:16 PM
    Sunday, October 5, 2014 11:05 PM

All replies

  • It's of no help but just for your information MS don't actually support unattended automation of Office Apps for just this reason.

    If you're running this as a scheduled task you could try setting a timeout value and aborting if it over-runs then re-attempt the process.

    • Marked as answer by Bill_Stewart Thursday, October 16, 2014 9:16 PM
    Sunday, October 5, 2014 11:05 PM
  • Aside from Alex's comments, which are correct, your problem description is far too vague to be of any use:

    Sometimes the script is blocked by excel – it is not continuing with the execution of the scripts.

    You are going to have to perform some analysis to discover the root cause. It is not possible for us to guess at the problem without having access to the system.


    -- Bill Stewart [Bill_Stewart]

    Monday, October 6, 2014 1:20 AM
  • There is no way to run Excel hidden when it wants to show a modal message.  YOU must disable all alerts or this will happen.  Alerts caused by a corrupt file cannot be disabled.

    As noted above - Microsoft does not support running Excel with no GUI.


    ¯\_(ツ)_/¯

    Monday, October 6, 2014 7:18 AM