Provided that self.excel represents the Excel.Application object, you
can use the following code to prevent macros from running
automatically:
self.excel.EnableEvents = false
book = self.excel.Workbooks.Open(file,ExcelConst::XlUpdateLinksNever)
self.excel.EnableEvents = true
/lasso
Thanks Lasso,
yes, self.excel represents the Excel.Application object:
class ExcelConst
# to be filled with all Excelconstants
# once excel is running
end
#---------------------------------------------------------------
# make an Excel class to simplify opening & closing of classes
# place this in a separate file, and just require it
#---------------------------------------------------------------
class Excel
attr_accessor :excel
def initialize
require 'win32ole'
@excel = WIN32OLE::new('Excel.Application')
if !(defined? ExcelConst::XlYes)
WIN32OLE.const_load(@excel, ExcelConst)
end
@excel.DisplayAlerts = false
@excel.Visible = false
yield self
@excel.Quit
end
def open_book file
self.excel.EnableEvents = false
book =
self.excel.Workbooks.Open(file,ExcelConst::XlUpdateLinksNever)
#self.excel.EnableEvents = true
yield book
self.excel.ActiveWorkbook.Close(0)
end
end
The reason why I posted the original message was, that excel opend
visible during runtime although I set
@excel.Visible = false
I thought the reason for that behavior could be conncted to macros.
But it wasn't. I inserted your code and still excel opens the workbook
during:
Excel.new do |xl| # instanciate excel
filesL.each_with_index do |file,i| # let's loop on each file
i=3-i # array index starts at 0
xl.open_book(file) do |workbook|
sheets = workbook.Worksheets("Statistik")
rows = sheets.UsedRange.Rows.Count
cells = sheets.Range("C1:E#{rows}")
cells.each do |cell| ...........
Any ideas?
Have a nice weekend,
uwe