Senz79
asked on
Copy Excel sheet between two workbooks
Hello
Please help me to
copy a sheet from workbook1 ----> Create a new sheet in workbook2 -----> paste the sheet from workbook1 to workbook2
Thanks Senz
Please help me to
copy a sheet from workbook1 ----> Create a new sheet in workbook2 -----> paste the sheet from workbook1 to workbook2
Thanks Senz
//OPEN TADDAM
Excel.Workbook _Sbook;
Excel.Worksheet _Ssheet;
string strExpEveSheet = @"D:\ExportEvent\EXPScript\exportevents-20100920.csv";
//OPEN NETEISS
Excel.Workbook _Dbook;
Excel.Worksheet _Dsheet;
string strNETEISSsrc = @"D:\ExportEvent\EXPScript\Network.xls";
_Sbook = ClsComm.OpenExcelWorkbook(strExpEveSheet);
ClsComm.excel.Visible = true;
_Sbook.Worksheets.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
//_Ssheet = (Excel.Worksheet)_Sbook.ActiveSheet;
//_Ssheet.Select(Type.Missing);
_Dbook = ClsComm.OpenExcelWorkbook(strNetworksrc);
ClsComm.excel.Visible = true;
_Dsheet = (Excel.Worksheet)_Sbook.ActiveSheet;
_Dsheet.Select(Type.Missing);
_Dsheet.UsedRange.Select();
_Dsheet.UsedRange.Copy(Type.Missing);
_Ssheet = (Excel.Worksheet)_Sbook.ActiveSheet;
_Ssheet.Select(Type.Missing);
_Ssheet.Paste(Type.Missing, Type.Missing);
How to: Copy Worksheets
http://msdn.microsoft.com/en-us/library/ms178800.aspx
http://msdn.microsoft.com/en-us/library/ms178800.aspx
To add a copied worksheet to a workbook in a document-level customization
Globals.Sheet1.Copy(missing, Globals.ThisWorkbook.Sheets[3]);
To add a copied worksheet to a workbook in an application-level add-in
Excel.Worksheet worksheet1 = ((Excel.Worksheet)Application.ActiveWorkbook.Worksheets[1]);
Excel.Worksheet worksheet3 = ((Excel.Worksheet)Application.ActiveWorkbook.Worksheets[3]);
worksheet1.Copy(missing, worksheet3);
ASKER
_Dbook = ClsComm.OpenExcelWorkbook(
ClsComm.excel.Visible = true;
_Dsheet = (Excel.Worksheet)_Dbook.Ac
_Dsheet.Select(Type.Missin
_Sbook = ClsComm.OpenExcelWorkbook(
ClsComm.excel.Visible = true;
_Sbook.Worksheets.Add(Type
_Ssheet = (Excel.Worksheet)_Sbook.Ac
_Ssheet.Select(Type.Missin
_Dsheet.Copy(Type.Missing,
I get the below error
System.Runtime.InteropServ
Message="Exception from HRESULT: 0x800A03EC"
Source="Interop.Excel"
ErrorCode=-2146827284
StackTrace:
at Excel._Worksheet.Copy(Obje
at ExportEvent.Program.OpenEx
at ExportEvent.Program.Main(S
at System.AppDomain._nExecute
at System.AppDomain.ExecuteAs
at Microsoft.VisualStudio.Hos
at System.Threading.ThreadHel
at System.Threading.Execution
at System.Threading.ThreadHel
InnerException:
My previous comment was for copying inside the same workbook ...
http://www.eggheadcafe.com/community/aspnet/66/10142380/copy-a-specific-worksheet-to-another-workbook.aspx
http://www.eggheadcafe.com/community/aspnet/66/10142380/copy-a-specific-worksheet-to-another-workbook.aspx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
example for usage:
CopyExcelWroksheet(@"c:\te mp\src.xls x", @"c:\temp\dest.xlsx", "Worksheet1");
CopyExcelWroksheet(@"c:\te
ASKER
It worked but there is a flaw
A new sheet to be created and then the data need to be pasted, in this code the existing sheet was deleted and new sheet with the copied data was pasted.
I need to keep the original sheet as it is.
A new sheet to be created and then the data need to be pasted, in this code the existing sheet was deleted and new sheet with the copied data was pasted.
I need to keep the original sheet as it is.
http://forums.asp.net/p/1457463/3340354.aspx
http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/b31bf687-2549-436a-8997-c11c9f3258ed