开发者

How to handle this exception related to Excel

In our application,user can export some data to an excel file.When he clicks export, we pop-up windows file dialog where he chooses an existing excel file to overwrite,or give a new name.But,when he overwrites an existing file,he is asked by windo开发者_C百科ws "does he want to replace",and if he clicks no,an exception is raised

Exception from HResult: at Microsoft.office.Interop.Excel.Workbook.Saveas

How can we detect this exception? Or,is it possible to detect "no" and handle it?


You can try to handle the Excel error following tips on this page : http://www.cpearson.com/excel/errorhandling.htm

First, set an :

On Error GoTo ErrHandle

Don't forget to put an :

Exit Sub

And then put :

ErrHandle:
'Use Err.Number (need to check which one it is though)
If Err.Number == 1 then
'Do what you want
End Sub

You just have to find which err number it is (e.g. by debugging) and treat this exception,

Hope that helps,

Regards,

Max

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜