LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem getting Excel_RangeAutoFit to work

I am not able to get the Excel_RangeAutoFit function to work.

 

Here is an edited code section I am running. All the lines work except the last one.

 

/* Select columns A to L and autoformat column width */
CA_VariantSetEmpty (&CellRangeV);
CA_VariantSetCString (&CellRangeV, "A:L");
errorCode = Excel_WorksheetActivate (ws_handle, NULL);
errorCode = Excel_WorksheetRange (ws_handle, &ErrorInfo, CellRangeV, CA_DEFAULT_VAL, &rangeHandle);
errorCode = Excel_RangeActivate (rangeHandle, &ErrorInfo, &axStatus);     
errorCode = Excel_RangeSelect (rangeHandle, &ErrorInfo, &axStatus);     

/* this line errors out */
errorCode = Excel_RangeAutoFit (rangeHandle, &ErrorInfo, &axStatus);

 

 

Thanks

0 Kudos
Message 1 of 5
(3,036 Views)

I have never seen a Range object selected with A:L

http://msdn.microsoft.com/en-us/library/bb178282%28v=office.12%29.aspx

0 Kudos
Message 2 of 5
(3,033 Views)

I also tried selecting it with a fully defined range as (A1:L50).

That did not work either.

 

I am just trying to auto size a set of columns.

Any other command to do this?

0 Kudos
Message 3 of 5
(3,023 Views)

 

Are you obtaining a value for ws_handle elsewhere in your code?

 

If it was me, I would have just

CA_VariantSetEmpty (&CellRangeV);
CA_VariantSetCString (&CellRangeV, "A1:L50");

errorCode = Excel_WorksheetRange (ws_handle, &ErrorInfo, CellRangeV, CA_DEFAULT_VAL, &rangeHandle);
errorCode = Excel_RangeAutoFit (rangeHandle, &ErrorInfo, &axStatus);

0 Kudos
Message 4 of 5
(3,018 Views)

Yes I do get the handle to the worksheet.

 

As a work around I am sucessfully sending this to fix the columns at a specific size:

 errorCode = Excel_SetProperty (rangeHandle, &ErrorInfo, Excel_RangeColumnWidth, CAVT_VARIANT, CA_VariantDouble(16.86));

 

So, I know the rangeHandle and ws_hadle are valid.

 

Thanks

 

JC

0 Kudos
Message 5 of 5
(3,015 Views)