Quantcast
Channel: LabWindows/CVI topics
Viewing all articles
Browse latest Browse all 5371

How To Move A Sheet In Excel

$
0
0

I created a new sheet in Excel. The Excel app does not allow the creation of a new sheet after the last sheet, you have to create a new sheet (the default is 'next to the last') and move it into the last sheet position, which is what I'm trying to do.

 

The code below ads the new sheet and works fine until the last function call, which returns an HRESULT of -2147467262. Can someone have a look and see what's wrong here?

 

		// Determine the number of sheets in the workbook
		ret = Excel_GetProperty (ExcelSheetsHandle, NULL, Excel_SheetsCount, CAVT_LONG, &sheetCount);
// Make a handle for the last sheet in the workbook ret = Excel_SheetsItem (ExcelSheetsHandle, NULL, CA_VariantInt(sheetCount), &ExcelSheetHandle);
// The Move function wants a VARIANT type not an object, so make a variant from the object handle of the last sheet in the workbook. ret = CA_VariantSetObjHandle (&LastSheetV, ExcelSheetHandle, CAVT_DISPATCH);
// Add the new sheet ret = Excel_SheetsAdd (ExcelSheetsHandle, NULL, CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL, &ExcelSheetHandle); // Now move it using the LastSheetV variant in the After position of the SheetsMove function call. ret = Excel_SheetsMove (ExcelSheetHandle, NULL, CA_DEFAULT_VAL, LastSheetV);
// >> ERROR << Halt and catch fire.

Anyone see what's wrong? Still learning ActiveX protocol.

 

And BTW, where does one find the HRESULT error codes?

 


Viewing all articles
Browse latest Browse all 5371

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>