Chapter 4. Automation

I was working on a project that required updating several spreadsheets on a regular basis. I wanted to open Excel with multiple worksheets, but doing it by hand was cumbersome (and Excel doesn’t allow you to pass multiple files on a command line). So, I took a few minutes to write the following little Ruby script:
classDailyLogsprivate@@Home_Dir="c:\\MyDocuments\\Documents\\"defdoc_listdocs =Array.new docs <<"Sisyphus Project Planner.xls"docs <<"TimeLog.xls"docs <<"NFR.xls"enddefopen_daily_logsexcel =WIN32OLE.new("excel.application") workbooks = excel.WorkBooks excel.Visible =truedoc_list.eachdo|f|beginworkbooks.Open(@@Home_Dir+ f,true)rescueputs"Cannot open workbook:",@@Home_Dir+ fendendexcel.Windows.Arrange(7)endendDailyLogs.daily_logs
Even though it didn’t take long to open the files by hand, the little time it took was still a waste of time, so I automated it. Along the way, I discovered that you can use Ruby on Windows to drive COM objects, like Excel.
Computers are designed to perform simple, repetitive tasks over and over really fast. Yet an odd thing is happening: people are performing simple, repetitive tasks by hand on computers. And the computers get together late at night and make fun of their users. How did this happen?
Graphical environments are designed to help novices. Microsoft created the Start button in Windows ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access