Question : Range.Copy() causes a -2146827284 COMException

Ok, I have a workbook open that has several worrksheets in it, I have an object that contains storage elements to be manipulated by a calling program. So, I have the need to copy a range of data from a worksheet into a Range Type memory variable so that I can manipulate the values w/out altering the worksheet.

The workbook opens fine; the worksheet navigation works fine; but when I try to copy the range of values - BOOM - COMException!

The target range is defined as a property on the object:
public Microsoft.Office.Interop.Excel.Range SurveyData { get; set; }

(Please excuse the use of numeric literals below, the format of the spreadsheets are very constant)
The object loading code in question:
            #region Lighting Survey Page:
            _oEx.ActivateWorksheet("Lighting Survey Page", true);
            cnt = _oEx.HowManyRowsHaveData(true, "A", 12, 0, false);
            if (cnt > 0)
            {
                cnt += 11;
                _oEx.SetActiveRange("A12:X" + cnt, true);
                _oEx.ActiveRangeSourceWB.Copy(this.SurveyData);  // Errors here!
            }
            #endregion

I have verified that the variable cnt is valid @ 164...
The spreadsheet range doesn't appear to me to be corrupted in any way...
There are fomulas embedded in the range; does that matter?

Offering the Max points due to the complexity - I need this COMException resolved as soon as practical! Thank you in advance!

Answer : Range.Copy() causes a -2146827284 COMException

I found the issue!!

The method: “_oEx.ActivateWorksheet("Lighting Survey Page", true)” was failing; but not reporting it! Fixed the underlying method to return a bool and by checking the result; I can control the application flow around the issue…

My thanks to anyone who saw this question and was attempting to answer it
Random Solutions  
 
programming4us programming4us