vba 在 Excel 中使用宏更改小数点分隔符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21252436/
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 01:28:56  来源:igfitidea点击:

Change decimal separator with macro in Excel?

excelexcel-vbadecimalseparatorvba

提问by user3215646

I want to change decimal separator from comma to point. How can I do this with macro?

我想将小数点分隔符从逗号更改为点。我怎样才能用宏做到这一点?

回答by CaBieberach

Actually you can do it.

其实你可以做到。

Sub Macro1()
    With Application
        .DecimalSeparator = "."
        .ThousandsSeparator = ","
        .UseSystemSeparators = false
    End With
End Sub

Importante Note:

重要提示:

This change will take effect only inside Excel and on ALL Excell files open. And the next time you open Excel, this settings will be active.

此更改仅在 Excel 内部和打开的所有 Excell 文件中生效。下次打开 Excel 时,此设置将处于活动状态。

You could record the state of this settings before changing them so that you can return the application to its original state.

您可以在更改这些设置之前记录它们的状态,以便您可以将应用程序返回到其原始状态。

回答by teylyn

You can't.

你不能。

The decimal separator is a part of your operating system's regional settings.

小数点分隔符是操作系统区域设置的一部分。

It cannot be changed on an application (Excel) level or a file (Excel workbook) level.

它不能在应用程序 (Excel) 级别或文件(Excel 工作簿)级别进行更改。

If you have problems with the decimal separator in a file that you want to use in Excel, please edit your question to state the real issue.

如果您想在 Excel 中使用的文件中的小数点分隔符有问题,请编辑您的问题以说明真正的问题。

Your system may use the . as a decimal, but the file you want to import uses a comma. Open the file in a text editor and replace commas with dots and dots with commas.

您的系统可能使用 . 作为小数,但您要导入的文件使用逗号。在文本编辑器中打开文件,用点替换逗号,用逗号替换点。

  • for example: replace all commas with # (or another character that is highly unlikely to appear anywhere in the file)
  • then replace all dots with commas
  • then replace all # with dots.
  • 例如:将所有逗号替换为 #(或其他极不可能出现在文件中任何位置的字符)
  • 然后用逗号替换所有点
  • 然后用点替换所有#。

Save the file and then import into Excel.

保存文件,然后导入 Excel。

回答by WolfsBane

Go to Options, and in the Advanced section you will find the option "Use system separator" . Deselect that and put in your own characters.

转到“选项”,在“高级”部分,您将找到“使用系统分隔符”选项。取消选择并输入您自己的字符。