in reply to
Win32::OLE(0.1702) error 0x80020011
I suspect that you had this script working in the past, but after you have upgraded the version of Windows (possibly to XP?) and also the version of office, it stopped working. Is that so?
The old version of office products and the XP versions are different. Old versions have a single main window, and workbooks open in the same window in MDI (multiple document interface) mode.
The new version of office products have multiple windows, one window for each active workbook. They group into a collection of windows for the same application. You will need to first determine the active document (or active workbook), and then operate on the active document.
I haven't run your code, so this is all guess work.