views:

1474

answers:

1

I'm trying to select the "used range". I get the worksheet's UsedRange, then I invoke the Select function on it. I receive HRESULT 0x800a03ec on the select call.

Here's the code:

COleVariant result;

HRESULT hr = AutoWrap(DISPATCH_METHOD, &result, irange, L"Select", 0);

I won't bother posting the code for the AutoWrap function (unless someone asks). It's pretty well-known and I haven't modified it.

I'm pretty sure that irange is good, because I tried some calls on it to verify that it has what I expect, and it does. If I iterate through it, I can see the content of each cell (and it's correct); the number of rows and columns returned is correct, and the "Address" property returned checks out.

Worksheet is not locked.

I've seen other problems posted having to do with Locale, and my system is set to U.S. English as is my user account. Neither has been changed.

Hope someone can help!

Update: I have also tried

hr = iRange->Select(vResult);

This does return S_OK, but it does not select the range. Normally, I can't directly call the functions in the iRange struct; the result is a gpf or access violation -- so I have to use the autowrap function (to drive an Invoke call). I'm not surprised this call doesn't work.

I have also tried opening the excel file in non-ReadOnly mode, in case I was locked. This didn't fix the problem. I can select individual cells by getting a single item (cell) from the range, and calling its Select, but I can't select the range.

+3  A: 

I found the answer to this question. This only appears to be a problem when used in the DSOFRAMER sample (Microsoft KB 311765). DSOFramer is a general purpose ActiveX control for embedding MS Office documents. The problem also only happens in a debug build; release builds are fine.

I also found a workaround that works on release or debug build: get any cell in the range (using get_Item), then call select on that item, then select again to de-select it. Once that's done, the select can be called on the range. Apparently, select cannot be called on the range if there is a cell already selected (or perhaps if the selection state is undefined).

Steve