Force numeric/language format to document

Asked

Viewed 337 times

3

Where work is very common we have problems with excel macros, which generate tables and charts, depending on the language and version of Excel the client is using.

How to force a language (for example English) and consequent numerical formats? That way a thirty percent would appear, for example, always as 30.00% and a thousand always as 1,000.00 independent of the user’s language?

PS.: I know it is possible to use .NumberFormat in each cell, but I’m looking for a global setting that solves all the numbers within the document.

  • Fully valid question. So far I have not found how to normalize the location of files generated via code.

  • @gmsantos believe that with the answer below is ok! I believe that when the mathiasfk test will put mark as answered.

1 answer

3


If you want to use the dot instead of the comma in all fields of the worksheet you can access the menu EXCEL > OPTIONS > ADVANCED > 'Use system separator' and define what you want.

To do this via code in VBA use the following function:

Function setSeparadorDecimal()
  With Application
    .DecimalSeparator = "."
    .ThousandsSeparator = ","
    .UseSystemSeparators = False
  End With 
End Function

As warned by our friend @mathiasfk, the above function changes the Applying and not only the active file, so if it is interesting to return the Excel decimal separator to the default, use the function below:

Application.UseSystemSeparators = True

I hope I’ve helped!

  • Thanks! In case I think I would solve only for that copy of Excel, in case, that of my machine. My big problem is that every customer can have a different configuration.

  • @mathiasfk edited the answer and I believe that this way he will be able to force the file to use the separator he wants. If the answer is correct, mark as solved. Abs!

  • Perfect! Exactly what I was looking for.

  • 1

    A warning to those who use this: This setting is saved in Excel even after the file is closed, so it is a good practice to return to the original configuration at the end of your macro. Application.UseSystemSeparators = True

Browser other questions tagged

You are not signed in. Login or sign up in order to post.