Hi Nicola, Put it in a method and call the method from within a loop:
require 'watir' include Watir url = "http://www.zoomerang.com/recipient/survey.zgi?p=WEB225WDYJNVDT" search_string = "questionnaire" $ie = IE.new $ie.goto(url) $ie.bring_to_front #ie.show_all_objects require 'win32ole' def fill_fields(worksheet_no) excel = WIN32OLE::new('excel.Application') workbook = excel.Workbooks.Open('C:\WATIR_RUBY\excel_testdata5.xls') worksheet = workbook.Worksheets(worksheet_no) #get hold of the first worksheet worksheet.Select @mydata = [] @mydata = worksheet.Range('a1:a6').value # The data is in cell a1 - a6 excel['Visible'] = false # hide the spreadsheet from view workbook.close excel.Quit $ie.text_field(:name, 'u_answer_58').set(@mydata[0].to_s) $ie.text_field(:name, 'u_answer_59').set(@mydata[1].to_s) $ie.text_field(:name, 'u_answer_60').set(@mydata[2].to_s) $ie.text_field(:name, 'u_answer_61').set(@mydata[3].to_s) $ie.text_field(:name, 'u_answer_62').set(@mydata[4].to_s) $ie.text_field(:name, 'u_answer_63').set(@mydata[5].to_s) end # call the method: for i in 1..5 fill_fields(i) end Note that I've changed ie to $ie making it global so it's visible inside the method. -Charley On 4/13/07, Nicola Kennedy <[EMAIL PROTECTED]> wrote:
Hi, Have written following script (which works! I'm getting there!) I now want to put a loop in so that when this is complete, it goes to the second worksheet in my excel file, basically starting the process from the beginning again and then inputs this information in the same fields. Can anyone help? TIA require 'watir' include Watir url = "http://www.zoomerang.com/recipient/survey.zgi?p=WEB225WDYJNVDT" search_string = "questionnaire" ie = IE.new ie.goto(url) ie.bring_to_front #ie.show_all_objects require 'win32ole' excel = WIN32OLE::new('excel.Application') workbook = excel.Workbooks.Open ('C:\WATIR_RUBY\excel_testdata5.xls') worksheet = workbook.Worksheets(1) #get hold of the first worksheet worksheet.Select @mydata = [] @mydata = worksheet.Range('a1:a6').value # The data is in cell a1 - a6 excel['Visible'] = false # hide the spreadsheet from view workbook.close excel.Quit ie.text_field(:name, 'u_answer_58').set(@mydata[0].to_s) ie.text_field(:name, 'u_answer_59').set(@mydata[1].to_s) ie.text_field(:name, 'u_answer_60').set(@mydata[2].to_s) ie.text_field(:name, 'u_answer_61').set(@mydata[3].to_s) ie.text_field(:name, 'u_answer_62').set(@mydata[4].to_s) ie.text_field(:name, 'u_answer_63').set(@mydata[5].to_s) _______________________________________________ Wtr-general mailing list [EMAIL PROTECTED] http://rubyforge.org/mailman/listinfo/wtr-general
_______________________________________________ Wtr-general mailing list [EMAIL PROTECTED] http://rubyforge.org/mailman/listinfo/wtr-general
