Hi All,
I am getting a PasteSpecial method of Range class failed" error
Please help code is below
Microsoft.Office.Interop.Excel.Application ExcelObj = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(path, 0, true, 1, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
Microsoft.Office.Interop.Excel.Sheets sheets = theWorkbook.Worksheets;
Microsoft.Office.Interop.Excel.Worksheet workSheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);
Range last = workSheet.Cells.SpecialCells(XlCellType.xlCellTypeLastCell,Type.Missing);
Range r1 = ((Microsoft.Office.Interop.Excel.Range)workSheet.Cells[1, 1]).EntireColumn;
r1.Insert(XlInsertShiftDirection.xlShiftToRight,XlInsertFormatOrigin.xlFormatFromLeftOrAbove);
Range r2 = (Microsoft.Office.Interop.Excel.Range)workSheet.Cells[1, 1];
r2.Select();
r2.FormulaR1C1 = "=LEFT(RC[1],100)";
r2.Select();
Range r3 = (Microsoft.Office.Interop.Excel.Range)workSheet.get_Range("A1","A160237");
r2.AutoFill(r3,XlAutoFillType.xlFillCopy);
r3.Copy(r3);
sheets.Add(Type.Missing, workSheet, 1, Microsoft.Office.Interop.Excel.XlSheetType.xlWorksheet);
Microsoft.Office.Interop.Excel.Worksheet workSheetA = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(2);
Range r4 = (Microsoft.Office.Interop.Excel.Range)workSheetA.Cells[1, 1];
r4.Select();
r4.PasteSpecial(XlPasteType.xlPasteValues, XlPasteSpecialOperation.xlPasteSpecialOperationNone,false,false);
Paste special is working fine in my VBA code
VBA code is as follow
Selection.Copy
Sheets("Sheet3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False