From: CC Chen Date: 2011-08-09T11:38:31+09:00 Subject: Re: Excel chart question Timothy Barnes wrote in post #1015519: > On Mon, Aug 8, 2011 at 7:40 AM, CC Chen wrote: > >> excel.Range("B3").Value = 17 >> >> excel.Range("A1:A3").Select(); >> > excel.Range("B1:B3").Select(); > >> Thanks, >> >> -- >> Posted via http://www.ruby-forum.com/. >> > > The problem is that once you create the first chart the range.select > method > is focused on the "chart sheet" and not the original sheet (with the > data). > Therefore you either need to set both ranges first: > > excel.Range("A1:A3").select > excel.Range("B1:B3").select > excelchart1 = workbook.Charts.add() > excelchart2 = workbook.Charts.add() > > or you need to set the focus back on the original worksheet: > > excel.Range("A1:A3").select > worksheet = workbook.Worksheets('Sheet1').select > excelchart1 = workbook.Charts.add() > excel.Range("B1:B3").select > excelchart2 = workbook.Charts.add() > > My preference would be the first plus associating the ranges with > variables > and not using select: > > range_1 = excel.range("A1:A3") > range_2 = excel.range("B1:B3") > excelchart1 = workbook.charts.add(range_1) > excelchart2 = workbook.charts.add(range_2) > > Timothy Sorry, I tried those methods but still had some problems. excel.Range("A1:A3").select excel.Range("B1:B3").select excelchart1 = workbook.Charts.add() excelchart2 = workbook.Charts.add() I used the method it could show two charts but the value were "B1 to B3". excel.Range("A1:A3").select worksheet = workbook.Worksheets('Sheet1').select excelchart1 = workbook.Charts.add() excel.Range("B1:B3").select excelchart2 = workbook.Charts.add() Try this method just only created one chart and the range were "A1 to A3". range_1 = excel.range("A1:A3") range_2 = excel.range("B1:B3") excelchart1 = workbook.charts.add(range_1) excelchart2 = workbook.charts.add(range_2) Try this way no chart was created and also showed some error messages. "method_missing":(in OLE method 'add':)(WIN32OLERuntimeError).... Thanks, -- Posted via http://www.ruby-forum.com/.