在 Excel VBA 中更改为加拿大 (CDN) 法语数字格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41467694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 11:49:08  来源:igfitidea点击:

Change to Canadian (CDN) French number formatting in Excel VBA

excel-vbanumber-formattingfrenchvbaexcel

提问by Greg

I would like to build a piece of code which can convert numbers in my workbook from English to French number formatting.

我想构建一段代码,可以将我的工作簿中的数字从英语转换为法语数字格式。

For example,

例如,

  • English formatting would be $1,000,000.99, and
  • French would be 1 000 000,99 $
  • 英文格式为$1,000,000.99, 和
  • 法语将是 1 000 000,99 $

I can not seem to find any default French codes built into excel and using a ,instead of a .for the decimal does not show numbers less than $1.

我似乎找不到任何内置在 excel 中的默认法语代码,并且使用 a,而不是 a.表示小数点不显示小于 $1 的数字。

Any assistance or advice is appreciated!

任何帮助或建议表示赞赏!

采纳答案by airstrike

To make the currency symbol appear to the right of your numbers, use the NumberFormatproperty of a Rangeobject and set it to:

要使货币符号出现在数字的右侧,请使用对象的NumberFormat属性Range并将其设置为:

  • For dollars: #,##0.00 [$$-C0C]
  • For euro: #,##0.00 [$-C0C]
  • 对于美元: #,##0.00 [$$-C0C]
  • 欧元: #,##0.00 [$-C0C]

The behavior of commas and periods for decimals and digit grouping is usually controlled by your Region and Language Settings in Windows.

用于小数和数字分组的逗号和句点的行为通常由 Windows 中的区域和语言设置控制。

You can change this setting application-wide (i.e. it will affect any workbook opened on your machine) by changing the values of Application.DecimalSeparatorand Application.ThousandsSeparatorin VBA. Alternatively, you can achieve the same effect by going to File > Options > Advanced and uncheck "Use system separators"

您可以申请范围内更改此设置改变的值(即它会影响您打开计算机上的任何工作簿)Application.DecimalSeparator,并Application.ThousandsSeparator在VBA。或者,您可以通过转到“文件”>“选项”>“高级”并取消选中“使用系统分隔符”来实现相同的效果

enter image description here

在此处输入图片说明

回答by G?T?

To get the code for any action in Excel:

要获取 Excel 中任何操作的代码:

  1. start recording a macro
  2. do what you want to replicate via code
  3. stop the recording
  4. check the macro code (ALT+F11)
  1. 开始录制宏
  2. 通过代码做你想复制的事情
  3. 停止录音
  4. 检查宏代码 (ALT+F11)

In this case applying the formatting gives this code:

在这种情况下,应用格式会给出以下代码:

Selection.NumberFormat = "#,##0.00 $"

Hope this helps.

希望这可以帮助。