Switch To..., Retry, Cancel

Written by Troy Howard

07 January 2009

Well, as much as I hate to admit it, I was recently working on VB6 application that uses Office COM automation. It needed to have Word and Excel do a few things while the main application waited.

Every time a user clicked on the UI, you'd get that beautiful dialog:

Switch To.., Retry, or Cancel

This application cannot be completed because the other application is busy. Choose 'Switch To' to activate the busy application and correct the problem.

This is particularly onerous because if the user does not click Switch To... both programs, the VB6 app AND the Office app sit around waiting for the user to do something. Yay!

Luckily I found the quick and dirty answer to this. Somewhere… Anywhere before the point that you make the COM call, just insert these two lines:

App.OleRequestPendingTimeout = 2147483647
App.OleServerBusyTimeout = 2147483647 

… and you never have to see that dialog again.