# Win32ole and excel and copy

**URL:** <https://www.ruby-forum.com/t/win32ole-and-excel-and-copy/75254>\
**Category:** Ruby\
**Created:** [November 8, 2006, 2:33pm UTC](https://www.ruby-forum.com/t/win32ole-and-excel-and-copy/75254 "2006-11-08T14:33:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [November 8, 2006, 2:33pm UTC](https://www.ruby-forum.com/t/win32ole-and-excel-and-copy/75254/1 "2006-11-08T14:33:31Z")

</div>

Hi all,

I use wind32ole to import data and create graphs into Excel. I find the  
graphs can’t be copied or resized. Any comments?

Thanks,

Li

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [November 8, 2006, 4:42pm UTC](https://www.ruby-forum.com/t/win32ole-and-excel-and-copy/75254/2 "2006-11-08T16:42:10Z")

</div>

Li Chen wrote:

> Hi all,
> 
> I use wind32ole to import data and create graphs into Excel. I find the  
> graphs can’t be copied or resized. Any comments?
> 
> Thanks,
> 
> Li

# Here is sample code to copy a chart in a worksheet:

require ‘win32ole’

xl=WIN32OLE::new(‘Excel.Application’)  
xl.Visible=1 #show excel

xl.Workbooks.Open(‘c:\testme.xls’) #will open a file

xl.sheets(1).activate #activate the sheet you want

xl.ActiveSheet.ChartObjects(“Chart 1”).Activate #activate the chart

xl.ActiveChart.ChartArea.Select  
xl.ActiveChart.ChartArea.Copy  
xl.Windows(“testme.xls”).Activate  
xl.Cells(50,1).Select # select row and col to paste chart  
xl.ActiveSheet.Paste

#xl.ActiveWorkbook.Close()  
#xl.Quit

#greg

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [November 8, 2006, 11:19pm UTC](https://www.ruby-forum.com/t/win32ole-and-excel-and-copy/75254/3 "2006-11-08T23:19:26Z")

</div>

Greg H. wrote:

> > # Here is sample code to copy a chart in a worksheet:
> 
> require ‘win32ole’
> 
> xl=WIN32OLE::new(‘Excel.Application’)  
> xl.Visible=1 #show excel
> 
> xl.Workbooks.Open(‘c:\testme.xls’) #will open a file
> 
> xl.sheets(1).activate #activate the sheet you want
> 
> xl.ActiveSheet.ChartObjects(“Chart 1”).Activate #activate the chart
> 
> xl.ActiveChart.ChartArea.Select  
> xl.ActiveChart.ChartArea.Copy  
> xl.Windows(“testme.xls”).Activate  
> xl.Cells(50,1).Select # select row and col to paste chart  
> xl.ActiveSheet.Paste
> 
> #xl.ActiveWorkbook.Close()  
> #xl.Quit
> 
> #greg

Hi Greg,

I try the script but I find it only open an designated file only. I  
still can’t copy the chart. BTW there is plug-in in Excel called Visual  
Basic editor. Is it the same as Visual Basic environment?

Thanks,

Li
