VBA Word - changing decimal separator

拜拜、爱过 提交于 2019-12-10 21:43:41

问题


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

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?


回答1:


Being not very patient I did it the "harder way". I declared public variable

Public strDecimal As String

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))

with

CDbl(Replace(strShort(5), ".", strDecimal))

and all write-outs like

Selection.TypeText Text:=CStr(Int(1000 * bondRadius) / 1000)

with

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.

I'll play a bit with info from barrowc's comment (thanx) to see if it's read only or read-write value.



来源:https://stackoverflow.com/questions/16191557/vba-word-changing-decimal-separator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!