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.
SetLocale
听起来像是解决我问题的完美解决方案,但是经过一分钟的深入研究,我发现 GetLocale
和 SetLocale
显然是
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.
当我将解析后的日期分配给String变量时,它会起作用 (我最终使用 MM/DD/YYYY
或 DD/MMM/YYYY
格式,取决于我是否有类型不匹配的情况,只要我使用 On Error Resume
),但我需要在 MM/DD/YYYY
日期类型/格式,以便将所有解析的日期与另一个单元格中的特定日期进行比较(尝试确定该站点自在特定单元格中输入日期以来是否有任何更新).
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).
我也尝试过尝试 TimeStamp = Format(TimeStamp,"MM/DD/YYYY")
(TimeStamp是包含解析日期的变量),但它似乎没有用-很可能是由于类型不匹配错误造成的.
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.
如果有人知道在链接的问题中使用的等效于 SetLocale
函数的VBA,让我尝试一下,我将不胜感激.如果没有,我将很乐意修改我的问题,并在此处添加我当前的代码,以尝试共同提出解决方案.
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.
感谢您的时间和帮助.
推荐答案
如果您知道它们都是美国格式的,则可以使用如下函数:
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
这篇关于VBA是否等效于VBScript的"SetLocale"功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!