# Trouble using WIN32OLE for excel

**URL:** <https://www.ruby-forum.com/t/trouble-using-win32ole-for-excel/117288>\
**Category:** Ruby\
**Created:** [October 15, 2007, 6:04pm UTC](https://www.ruby-forum.com/t/trouble-using-win32ole-for-excel/117288 "2007-10-15T18:04:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![haleythrapp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/48db29/32.png) [@haleythrapp](https://www.ruby-forum.com/u/haleythrapp)\
**Post date:** [October 15, 2007, 6:04pm UTC](https://www.ruby-forum.com/t/trouble-using-win32ole-for-excel/117288/1 "2007-10-15T18:04:14Z")

</div>

I am trying to do some things that seem pretty basic to me using excel.  
Basically, I have a two column spreadsheet that I would like to make a  
scatterplot out of. I am able to create a chart, but I run into issues  
as soon as I try to give it a title. Any ideas? Also, if there are any  
experts out there, I am looking for a good reference for using the  
WIN32OLE in ruby. I am not very experienced with the WIN32OLE. I have  
also tried setting curr\_chart.HasTitle and  
curr\_chart.ChartTitle.Characters as I have seen in other threads, but  
none of these work for me. Is it possible I am missing a package even  
though I am able to handle all the other work I have tried with Excel?

require ‘win32ole’  
excel = WIN32OLE.new(“excel.application”)  
excel[‘Visible’] = TRUE

module ExcelConsts  
end

WIN32OLE.const\_load(excel, ExcelConsts)

workbook = excel.Workbooks.Add  
worksheet = workbook.Worksheets(1)

_snip_

charts = excel.Charts  
charts.Add

curr\_chart = excel.Charts(1)  
curr\_chart.Activate  
curr\_chart.ChartType=ExcelConsts::XlLineMarkers  
curr\_chart.ChartTitle.Text = “Testing chart title”

The error I am getting:

parse\_sizeVlatency.rb:118:in `method\_missing’: (WIN32OLERuntimeError)  
OLE error code:800A03EC in Microsoft Office Excel  
Unable to set the Text property of the ChartTitle class  
HRESULT error code:0x80020009  
Exception occurred. from parse\_sizeVlatency.rb:118

Thanks!

---

<div class="post-metadata">

**Author:** ![haleythrapp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/48db29/32.png) [@haleythrapp](https://www.ruby-forum.com/u/haleythrapp)\
**Post date:** [October 15, 2007, 9:25pm UTC](https://www.ruby-forum.com/t/trouble-using-win32ole-for-excel/117288/2 "2007-10-15T21:25:26Z")

</div>

On Oct 15, 12:04 pm, Haley T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> worksheet = workbook.Worksheets(1)
> 
> Posted viahttp://www.ruby-forum.com/.  
> This is what I found in the Microsoft Office Excel 2003 Visual Basic  
> Reference (VBAXL10.CHM), perhaps it will help.

Using the ChartTitle Object  
Use the ChartTitle property to return the ChartTitle object. The  
following example adds a title to embedded chart one on the worksheet  
named “Sheet1.”

With Worksheets(“sheet1”).ChartObjects(1).Chart  
.HasTitle = True  
.ChartTitle.Text = “February Sales”  
End With

Remarks  
The ChartTitle object doesn’t exist and cannot be used unless the  
HasTitle property for the chart is True.

This might work … not tested  
curr\_chart.HasTitle = ‘True’  
curr\_chart.ChartTitle.Text = “Testing chart title”
