简体   繁体   中英

Delete Excel sheet randomly fails

I am trying to delete Excel sheet via C++ code but randomly it fails. Here is the code:

HRESULT hr = AutoWrap(DISPATCH_METHOD, NULL, pXlSheet, L"Delete", 0);

This function returns S_OK even delete sheet failed but the sheet isn't deleted from the workbook.

Note: The system gives error sound, if delete sheet failed.

This error occurs because while deleting sheets sometimes warning prompt appears even deleting empty sheet.

To suppress warning prompt i used the below snippet and it works fine.

Code snippet:

VARIANT vBool;
vBool.vt=VT_BOOL;
vBool.boolVal=FALSE;

hr = AutoWrap(DISPATCH_PROPERTYPUT, NULL, _pXlApp, L"DisplayAlerts",1,vBool);

This method returns S_OK:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM