2 min readfrom Microsoft Excel | Help & Support with your Formula, Macro, and VBA problems | A Reddit Community

Italian locale settings break Excel Formulas in my code

Our take

Are you frustrated by Excel formulas breaking due to locale settings? If you're working with Italian settings and encountering the dreaded #NOME? errors, you're not alone. Many users face similar challenges when transitioning automation code across different machines. In this exploration, we’ll uncover a more robust, locale-agnostic approach that ensures your formulas perform seamlessly, regardless of language settings. Dive in to discover practical solutions that enhance your Excel experience and streamline your workflow—no more workarounds, just reliable results.

I wrote a small Excel COM automation code in Ruby that works on my machine.

Since everything worked fine, I have decided to test it on a client machine.

Only formulas didn't work.

I always get #NOME? for cells that use them (language is Italian).

When I download the Excel file and open it on my machine I get the same #NAME? error.

After searching for solutions, I found only FormulaLocal alternative but I do not like it, I have a bad feeling this is a workaround, not a production-quality approach.

Below is the minimal Ruby code that reproduces the issue (in case it will help someone):

#frozen_string_literal: false require 'win32ole' application = WIN32OLE.new('Excel.Application') application.visible = true workbook = application.Workbooks.Add(); worksheet = workbook.Worksheets(1); # Example input data (replace with your own array) texts = [ 'TEST', '123456ADFG' ] texts.each_with_index do |text, index| worksheet.Cells(index + 1, 1).Value = text end # Make column A width match the widest cell content worksheet.Columns('A').AutoFit dates = [ '2024-09-16', '2024-09-22' ] dates.each_with_index do |date, index| worksheet.Cells(1, index + 2).Value = date end worksheet.Columns('B:C').AutoFit worksheet.Range('B2').Formula = '=ISOWEEKNUM(B1)' numbers = [ 1.35, 2.65 ] numbers.each_with_index do |number, index| worksheet.Cells(1, index + 4).Value = number end worksheet.Columns('D:E').AutoFit worksheet.Range('D1:E1').NumberFormat = '0.00' # using absolute references removes triangle popup in Excel when the formula is entered, # and it also allows you to copy the formula down without changing the reference range worksheet.Range('D2').Formula = '=SUM($D$1:$E$1)' worksheet.Range('D2').NumberFormat = '0.00' worksheet.Range('D3').Formula = '=(SUM($D$1:$E$1) * 1.2)/3.0' worksheet.Range('D3').NumberFormat = '0.00' XL_OPENXML_WORKBOOK = 51 # .xlsx output_path = File.join(File.dirname(File.expand_path(__FILE__)), 'output.xlsx') output_path = output_path.tr('/', '\\') begin previous_alerts = application.DisplayAlerts application.DisplayAlerts = false workbook.SaveAs(output_path, XL_OPENXML_WORKBOOK) puts "Saved Excel file to: #{output_path}" ensure application.DisplayAlerts = previous_alerts end begin workbook.Close(0) rescue WIN32OLE::RuntimeError => e puts "Error closing workbook: #{e.message}" end begin application.Quit rescue WIN32OLE::RuntimeError => e puts "Error quiting Excel: #{e.message}" end # Help Windows release COM references so Excel.exe doesn't linger worksheet = nil workbook = nil application = nil GC.start 

Is there a locale-agnostic approach that works for me?

submitted by /u/NewSerbianGuy
[link] [comments]

Read on the original site

Open the publisher's page for the full experience

View original article