Application.DecimalSeparator问题 [英] Application.DecimalSeparator issue
问题描述
我的区域使用,"作为小数点分隔符.当我在Excel 2013中运行以下代码以导入使用."的数字时作为小数点分隔符,我没有任何错误.
My region uses "," as decimal separator. When I run the following code in Excel 2013 to import a number that uses "." as decimal separator I get no errors.
Dim strGetResult As String
strGetResult = httpObject.responseText
strGetResult = Replace(strGetResult, ".", Application.DecimalSeparator)
但是当我在Excel 2010中尝试同样使用``,''作为小数点分隔符的相同代码时,我不会得到相同的结果.调试显示Application.DecimalSeparator =."这是没有意义的,因为数字在该Excel中以,"分隔符输入.
But when I try this very same code in Excel 2010 that also uses "," as the decimal separator I don´t get the same result. Debugging shows that Application.DecimalSeparator = "." That makes no sense since numbers are input with "," separator in that Excel.
知道为什么会这样吗?
推荐答案
I had the same issue and managed to find the answer in this thread.
Application.DecimalSeparator仅在用户没有具有UseSystemSeparators选项已选中.
Application.DecimalSeparator is only relevant if the user doesn't have the UseSystemSeparators option checked.
例如,如果Application.UseSystemSeparators = True,则Application.DecimalSeparator的值不反映Excel实际使用的内容.如果在适用于Application.DecimalSeparator的MSDN文档中进行了描述,那就太好了.,但不是.
E.g., if Application.UseSystemSeparators = True, the value of Application.DecimalSeparator doesn't reflect what Excel actually uses. It would have been nice if this was described in the MSDN docs for Application.DecimalSeparator, but it isn't.
mrexcel线程还包含一个优雅的解决方案.而不是调用Application.DecimalSeparator,而是创建一个函数
The mrexcel thread also contains an elegant solution; instead of calling Application.DecimalSeparator, create a function
Public Function GetDecimalSeparator()
GetDecimalSeparator = Mid(Format(1000, "#,##0.00"), 6, 1)
End Function
,然后呼叫它.我使用了这种方法,它似乎可以正常工作.
and call that instead. I used this approach and it seems to work fine.
这篇关于Application.DecimalSeparator问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!