By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,792 Members | 1,684 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,792 IT Pros & Developers. It's quick & easy.

Copy worksheet not working

P: 1

when I tried to copy a worksheet programmatically in Excel 2007 the chartObjects are not getting copied. I am getting empty charts inside my new worksheet. This is working in Excel 2003.

Excel.Application.Worksheets("Sheet1").ChartObject s.Count //I am getting 2 here.

Excel.Application.worksheets("Sheet1").Copy After:= Excel.Application.Worksheets("Sheet2")

Excel.Application.Worksheets("Sheet1 (2)").ChartObjects.Count // I am getting zero here.

Please advise me.

Sep 16 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 112
I tested this in xl 2003 and assume it is the same. You need to invoke the copy method of the chartobjects, not the sheet itself. Such as:

Expand|Select|Wrap|Line Numbers
  1. Excel.Worksheets("Sheet1").ChartObjects.Copy
  2. Excel.Worksheets("Sheet2").Paste
Might be a better way but that will copy the chart object
Sep 19 '08 #2

P: 2
I have the same issue with C#. I need to copy the contents of one worksheet (Excel.Worksheet) to another worksheet. Everything gets copied (including pivot charts) when I execute the code for the 1st time. But when I execute the code again, the charts (pivot charts) in the source worksheet dont get copied to the destination worksheet in Excel 2007. This works fine in Excel 2003.
I'm using .NET 2.0!
can you please help me on this...

this is the code I'm using;
Expand|Select|Wrap|Line Numbers
  1.         public static void copy(Excel.Worksheet src, Excel.Worksheet dest)
  2.         {
  3.             Excel.Range range;
  4.             Excel.Range range2;
  6.             range = src.get_Range(src.Cells[1, 1], src.Cells[src.Rows.Count, src.Columns.Count]); 
  7.             range2 = dest.get_Range(dest.Cells[1, 1], dest.Cells[1, 1]);
  8.             range.Copy(range2);
  9.         }
Aug 10 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.