Unable to set the DisplayAlerts property of the Application class

谁说我不能喝 提交于 2020-01-15 03:49:08

问题


I am intermittently getting the following exception:

It does not occur if I step through the code and I'm having trouble working out how to reproduce it reliably. The inner exception is null.

I have search the web and found a C++ MFC programmer cam across the same thing but no answers: http://www.excelforum.com/excel-programming/555121-unable-to-set-displayalerts-property.html

I also have read up on another possible cause unfortunately is unrelated as its to do with opening a spreadsheet via IE.

Can someone please shed light on what is going on here? I would much prefer to know the root cause and code around it rather than using a try-catch. Thanks for any advice.

ps I didn't write this code (there would be a bool parameter for true false if I did), I'm just new to this project and want to clean it up a bit and make it more robust.


回答1:


You need to add exception handling to capture and report the ErrorCode, as suggested in the troubleshooting tips, then determine what Excel is complaining about.

This could be caused by a number of different issues, but without the ErrorCode, you are flying in the dark. Once you figure out the ErrorCode, if it is innocuous you could just trap the exception and ignore it.

The hex error code is returned in the ErrorCode property of the COMException that is thrown in this case. I'm not sure if the message will be in that list you provided, but it certainly doesn't hurt to look there.



来源:https://stackoverflow.com/questions/9763622/unable-to-set-the-displayalerts-property-of-the-application-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!