VBA相当于VBScript的“SetLocale”函数?

时间:2021-03-18 02:27:46

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听起来像是我的问题的完美解决方案,但是经过一分钟的深入研究之后,我发现GetLocale和SetLocale在VBA中显然是不支持的。

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

的工作当我解析日期分配给一个字符串变量(我最后一列使用MM / DD / YYYY或DD /嗯/ YYYY格式取决于是否我有一个类型不匹配,只要我使用错误的简历),但我需要他们在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 = Format,“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. 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.

如果有人知道一个VBA等效的SetLocale函数用于我的链接问题,我将非常感激。如果没有的话,我很乐意修改我的问题,并在这里添加我当前的代码,尝试一起敲定一个解决方案。

Thank you for your time and your help.

谢谢您的时间和帮助。

1 个解决方案

#1


1  

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

#1


1  

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