Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'win32ole'
ex = WIN32OLE.new("Excel.Application")
fso = WIN32OLE.new("Scripting.FileSystemObject")
files = ["Book1.xlsx", "Book2.xlsx"]
book = ex.Workbooks.Add
files.each { |file|
file = fso.GetAbsolutePathName(file)
book1 = ex.Workbooks.Open(file)
book1.Sheets(1).Copy(After: book.Sheets(book.Sheets.Count))
book1.Close
}
book.Sheets(1).Delete
book.SaveAs("C:\\Users\\sakai\\Documents\\test.xlsx")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment