全球VBA日期格式和小数点分隔符 [英] Global VBA date format and decimal separator

查看:338
本文介绍了全球VBA日期格式和小数点分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在PC上全局更改VBA设置来接受指定格式的日期和编号? (在我的情况下dd / mm / yyyy和逗号)

更改Excel设置并不能解决问题。



作为一个小型的VBA开发者,我主要是创建用户表单来进行数据输入和验证。除了一些基本的访问权限之外,它还使用户(主要是客户端的雇佣兵)免于在数据库中发作并破坏数据库。



但是,在表单的提交中,文本框的值被临时保存在电子表格的单元格中。不知何故,在这个步骤日期得到加扰,在某些情况下,小数点后3位数字乘以一千(例如1/2/2000转到2/1/2000和1,234转1234)。它破坏了这些应用程序的全部目的 - 数据被破坏。

我已经能够使用格式(表达式,格式) 函数,但必须在每次添加日期或某个精度数字时应用,甚至在某些辅助任务上使用。



这是一个经常性的问题,因为作为一个巴西人,日期被格式化为dd / mm / yyyy,小数点分隔符在我的本地用户几乎100%是,(逗号)。

有人有类似的问题吗?

TIA

Excel没有默认的日期格式。 Excel使用窗口系统日期格式设置。您可以通过转到控制面板 - >更改日期,时间和数字格式来更改您的系统设置。



将Windows 7,8.1和Windows 10中的日期格式更改为dd-mm-yyyy






Windows系统设置为dd-mm-yyyy,则CDate将预期字符串位于dd-mm-yyyy。

lock <

范围(A1)。Value = CDate(11/01/2016)


结果: 2016年1月11日星期一

Is there a way to change VBA settings globally on PC to accept dates and number on a specified format? (on my case dd/mm/yyyy and comma)

Changing Excel settings doesn't solve it for me.

As an small time VBA developer, I'm mostly creating userforms for data input and validation. Alongside with some basic access privileges, It keeps users (mostly an client's hired arms) from nosing on the database and corrupting it.

But, on form's submitting, the textbox values are saved temporally on spreadsheet's cells. Somehow on this step dates get scrambled and in some cases an 3 decimal places numeric gets multiplied by a thousand (e.g. 1/2/2000 turn to 2/1/2000 and 1,234 turn 1234). It defeats the whole purpose of those applications - data gets corrupted.

I've been able to workaround these using the Format(expression, format) function, but that must be applied every time an date or some precision number is added, or even used on some auxiliary task.

This is an recurrent problem for me because, as an Brazilian, dates are formatted as dd/mm/yyyy and decimal separator is ","(comma) on practically 100% of my local users.

Anybody had similar problems?

TIA

解决方案

Excel doesn't have a default date format. Excel uses the Window System Date format settings. You can change you system setting by go to Control Panel -> Change date, time and number formats.

Change Date Format in Windows 7, 8.1 and Windows 10 to dd-mm-yyyy


After adjusting the Windows System Settings to dd-mm-yyyy, CDate will expect strings to be in the dd-mm-yyyy.

Range("A1").Value = CDate( "11/01/2016" )

Result: Monday, January 11, 2016

这篇关于全球VBA日期格式和小数点分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆