Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am trying to copy a sheet from one workbook to another workbook.Below is the code i had used. With this code i am able to copy the whole sheet but the problem is it is not carrying the formatting in the source sheet

C# Code used:
C#
objSourceWorkbook = ExcelApp.Workbooks.Open("Source Workbook Path", Type.Missing, true, Type.Missing,Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,Type.Missing);
objDestWorkbook = ExcelApp.Workbooks.Open("Dest Workbook Path", Type.Missing, true, Type.Missing,"Password to open the workbook", Type.Missing, Type.Missing, Type.Missing, Type.Missing,Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,Type.Missing);
objSheet = (Excel.Worksheet)objSourceWorkbook.Sheets["Sheet Name"];
ExcelApp.DisplayAlerts = false;
objSheet.Copy((Excel.Worksheet)objSourceWorkbook.Sheets[1], Type.Missing);
objDestWorkbook.Save();
ExcelApp.DisplayAlerts = true;

Please help me where am i doing wrong.

Thanks,
-Dileep
Posted
Updated 8-Dec-15 20:25pm
v2

1 solution

 
Share this answer
 
Comments
Member 11758880 9-Dec-15 2:44am    
No this is throwing COM exception

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900