08-16-2017 10:59 AM
Hello,
I have the need to select adjacent cells in Excel an merge them together using the ActiveX connection in LabWindows/CVI 2013 SP2. I see there is the function "Excel_RangeMerge(Object Handle, Error Info, Across)" that is in the Microsoft Excel 9.0 Object library. Is this the function I need to use to accomplish what I need? If so, how do I use it? Is the Object Handle the worksheet handle? I've also tried the "Excel_SetProperty (, NULL, Excel_RangeMergeCells, CAVT_VARIANT, );" without any luck. I've changed the CAVT_VARIANT to CAVT_STRING and added the 2 cells I wanted merged, but that didn't work as well.
08-17-2017 10:42 AM
Hi ragelbmann,
Could you point me to the documentation you are referring to?
Thanks,
Mitchell | NI
08-17-2017 11:19 AM
I have the excelreport.fp instrument file loaded which I can select the Microsoft Excel 9.0 Object library in the Instruments section. When I select the 'Excel_SetProperty' function, I can change the Property ID to "MergeCells" but I am not sure what the Property Type (defaults to CAVT_VARIANT) should be as well as the Value.
The functions looks like this: Excel_SetProperty (ObjectHandle, NULL, Excel_RangeMergeCells, CAVT_VARIANT, Value); I am assuming the ObjectHandle should be the Worksheet handle. The Excel Report library doesn't have a function to merge cells.
08-17-2017 11:20 AM - edited 08-17-2017 11:21 AM
Have you familiarized yourself with the Range Object?
https://msdn.microsoft.com/en-us/vba/excel-vba/articles/range-object-excel
The Merge Cells functionality lies within this object hierarchy
08-17-2017 11:30 AM
I have, but I am programming in C and not VBA.
08-17-2017 12:05 PM
I finally got it to work. Here is what I did:
CAObjHandle ExcelSheetHandle;
CAObjHandle ExcelRangeHandle;
VARIANT MyCellRangeV;
ERRORINFO ErrorInfo;
// Open new Range for Worksheet
error = CA_VariantSetCString(&MyCellRangeV, "E1:F1");
error = Excel_WorksheetRange(ExcelSheetHandle, NULL, MyCellRangeV, CA_DEFAULT_VAL, &ExcelRangeHandle);
// Make range Active
error = Excel_RangeActivate(ExcelRangeHandle, &ErrorInfo, NULL);
// Merge the cells
error = Excel_SetProperty(ExcelRangeHandle, NULL, Excel_RangeMergeCells, CAVT_BOOL, VTRUE);