问题描述
我周围的一些人在 windows/office 中使用国家本地化.不幸的是,这导致我的宏无法做简单的数学运算,因为它们使用逗号作为小数点位置,而我编辑的 pov-ray 文件仅使用逗号作为列表分隔符,点作为小数点.我知道在 Excel 中可以使用
Some people around me using national localization in windows/office. Unfortunately this leads to situation where my macros fail to do simple math as they using comma for decimal position and the pov-ray files, that I editing, use comma only for list separator and point for decimal one. I know that in Excel one can override system decimal separator using
With Application.
.DecimalSeparator = "."
.ThousandsSeparator = ","
.UseSystemSeparators = False
End With
然而,在 MS Word 中没有像 DecimalSeparator 这样的应用程序属性.MS Word 中是否有一种简单的方法可以在宏运行时覆盖系统分隔符?还是我需要在阅读 povray 文件时费力地替换它们?
There is however no such property of Application like DecimalSeparator in MS Word. Is there in MS Word a simple way to overwrite system separator for the time a macros is running? Or do I need to go hard way and replace them during reading of povray files?
推荐答案
由于不是很耐心,我采用了更难的方式".我声明了公共变量
Being not very patient I did it the "harder way". I declared public variable
Public strDecimal As String
然后在 main sub 的开头我设置它的值:
and then on the beginning of main sub I set its value with:
strDecimal = Application.International(wdDecimalSeparator)
然后在源代码中我替换了所有读入内容,如
Then in source I replaced all read-ins like
CDbl(strShort(5))
与
CDbl(Replace(strShort(5), ".", strDecimal))
以及所有类似
Selection.TypeText Text:=CStr(Int(1000 * bondRadius) / 1000)
与
Selection.TypeText Text:=CStr(Replace(Int(1000 * bondRadius) / 1000, strDecimal, "."))
它不像覆盖系统设置那么优雅,但它花费了我不多的时间并且对我有用.如果有人可以看到原因,为什么它偶尔会失败,请留下一些评论.
It's not as elegant as overwriting systems setting but it took me not too much time and it works for me. If anyone can see reason, why it should on occasion fail, please leave some comments.
我将使用 barrowc 的评论 (thanx) 中的信息来查看它是只读还是读写值.
I'll play a bit with info from barrowc's comment (thanx) to see if it's read only or read-write value.
这篇关于VBA Word - 更改小数点分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!