"PasteSpecial method of Range class failed" when range Number of Rows > 2000

E

eskimo2

I am having a problem with the Range.PasteSpecial Method, in C#..

Below is my code...

Basically, I am trying to copy the format from the ENTIRE first row,
and paste it
to the other rows in teh document...

this code WORKS FINE when the paste-to range is only like 200 lines,
or less...

When the PasteTo range is like 5000,10000 (keep in mind the copied
range is still just one measly row, so the clipboard shouldn't be
getting over flowed), etc. this is where I received the following
error

"


Excel.ApplicationClass ex =
new Microsoft.Office.Interop.Excel.ApplicationClass();
(ex as Excel.Application).Visible = true;
Excel.Workbook wb = (ex as
Excel.Application).Workbooks.Open(
_excelPath,missing,missing,missing,

missing,missing,missing,missing,missing,missing,missing,
missing,missing,missing,missing);

wb.Activate();
Console.WriteLine("done with excel lo");
Excel.Worksheet ws = wb.ActiveSheet as Excel.Worksheet;
Excel.Range r = ws.get_Range("A14", "U14");
r = r.EntireRow;

ex.CutCopyMode = Excel.XlCutCopyMode.xlCopy;
r.Copy(missing);
Excel.Range r2 = ws.get_Range("A15", "U5000"); //WHEN you
put in U1000/U2000, it takes a long time, but it still works.....

ex.ScreenUpdating = false;

try
{

r2.PasteSpecial(Microsoft.Office.Interop.Excel.XlPasteType.xlPasteFormats,

Microsoft.Office.Interop.Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone,
missing, missing);
}
catch (Exception ex1)
{
Console.Error.WriteLine(ex1.Message);
}
 
Top