LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Merging cells in Excel using ActiveX

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.

0 Kudos
Message 1 of 6
(2,982 Views)

Hi ragelbmann,

 

Could you point me to the documentation you are referring to?

 

Thanks,

 

Mitchell | NI

0 Kudos
Message 2 of 6
(2,942 Views)

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.

 

 

 

0 Kudos
Message 3 of 6
(2,938 Views)

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 

0 Kudos
Message 4 of 6
(2,936 Views)

I have, but I am programming in C and not VBA.

0 Kudos
Message 5 of 6
(2,933 Views)

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);   

0 Kudos
Message 6 of 6
(2,928 Views)