简体   繁体   English

VBA是否等效于VBScript的“ SetLocale”功能?

[英]VBA equivalent to VBScript's 'SetLocale' function?

To summarize my problem, I'm currently having the exact same issue as the person from this question here . 总结一下我的问题,我现在正和这里遇到这个问题的人完全一样。 I'm trying to parse a US date into an Excel sheet that has German as default and gives me a type mismatch on most of the dates because of it. 我正在尝试将美国日期解析为默认为德语的Excel工作表,并因此而在大多数日期上给我提供类型不匹配的信息。

SetLocale sounded like the perfect solution to my issue, but after a minute of further research I discovered that GetLocale and SetLocale are apparently not supported in VBA. SetLocale听起来是解决我的问题的完美解决方案,但是经过一分钟的深入研究,我发现VBA显然支持GetLocaleSetLocale

It sort of worked when I assigned the parsed date to a String variable (I end up with a column using either MM/DD/YYYY or DD/MMM/YYYY format depending on whether or not I had a type mismatch, as long as I use On Error Resume ), but I need them in a MM/DD/YYYY date type/format in order to compare all the parsed dates to a specific date in another cell (attempting to determine if the site has had any updates since the date entered in the specific cell). 当我将解析的日期分配给String变量时, 这种方法就可以工作了(我最终会使用MM/DD/YYYYDD/MMM/YYYY格式生成一列,具体取决于我是否有类型不匹配的情况,只要我使用On Error Resume ),但是我需要它们采用MM/DD/YYYY日期类型/格式,以便将所有解析的日期与另一个单元格中的特定日期进行比较(试图确定该网站自该日期以来是否有任何更新在特定单元格中输入)。

I've also tried doing TimeStamp = Format(TimeStamp, "MM/DD/YYYY") (TimeStamp being a variable containing the parsed date), but it doesn't seem to be working- most likely due to the type mismatch error. 我也尝试过执行TimeStamp = Format(TimeStamp, "MM/DD/YYYY") (TimeStamp是包含解析日期的变量),但它似乎不起作用-可能是由于类型不匹配错误。

If anyone knows a VBA equivalent of the SetLocale function used in the linked question for me to try out, I would greatly appreciate it. 如果有人知道在链接的问题中使用的等效于SetLocale函数的VBA让我尝试一下,我将不胜感激。 If there isn't any, I'll be happy to amend my question and add my current code here to try and hammer out a solution together. 如果没有,我将很乐意修改我的问题,并在此处添加我当前的代码,以尝试共同提出解决方案。

Thank you for your time and your help. 感谢您的时间和帮助。

If you know they are all in US format, you can use a function like this: 如果您知道它们都是美国格式的,则可以使用如下函数:

Function ConvertUSDate(sDate) As Date
    ConvertUSDate = Evaluate("DATEVALUE(""" & sDate & """)")
End Function

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM