date格式从VBA导出从Outlook更改为Excel

这在过去几天一直在我的脑海里有点奇怪。

我一直在更新Outlook中的一个macros,它将详细信息导出到Excel中。

到目前为止,macros一直工作正常,愉快地出口发件人,主题和date发送和接收没有问题。

我添加了一些信息,以便我可以捕获邮件已被回复/转发的时间和date,但这是事情出错的地方。

在运行代码的时候,如果我把一个Debug.Print放在variables上,并保存回复/转发的date,它会以正确的格式(dd / mm / yyyy hh:mm:ss)打印出来,但是当它popup时,原因是input为mm / dd / yyyy hh:mm:ss(但仅适用于月份<= 12的date)。

我检查了电脑的区域设置(实际上我已经在2台不同的机器上试过了),并且看不到任何会导致改变的东西。

我使用的代码如下,有没有人有任何想法?

'this is the part that exports to Excel intColumnCounter = intColumnCounter + 1 Set rng = wks.Cells(intRowCounter, intColumnCounter) rng.Value = GetLastVerb(msg) Debug.Print GetLastVerb(msg) Public Function GetLastVerb(olkMsg As Outlook.MailItem) As String Dim intVerb As Integer intVerb = GetProperty(olkMsg, "http://schemas.microsoft.com/mapi/proptag/0x10810003") Select Case intVerb Case 102 Debug.Print ("Reply to Sender") GetLastVerb = GetLastVerbTime(olkMsg) Case 103 Debug.Print ("Reply to All") GetLastVerb = GetLastVerbTime(olkMsg) Case 104 Debug.Print ("Forward") GetLastVerb = olkMsg.ReceivedTime Case 108 Debug.Print ("Reply to Forward") GetLastVerb = GetLastVerbTime(olkMsg) Case Else Debug.Print ("Unknown") GetLastVerb = "Not replied to" End Select End Function Public Function GetProperty(olkItm As Object, strPropName As String) As Date Dim olkPA As Outlook.PropertyAccessor Set olkPA = olkItm.PropertyAccessor GetProperty = olkPA.UTCToLocalTime(olkPA.GetProperty(strPropName)) Set olkPA = Nothing End Function Public Function GetLastVerbTime(olkItm As Object) As Variant GetLastVerbTime = GetDateProperty(olkItm, "http://schemas.microsoft.com/mapi/proptag/0x10820040") End Function Public Function GetDateProperty(olkItm As Object, strPropName As String) As Date Dim olkPA As Outlook.PropertyAccessor Set olkPA = olkItm.PropertyAccessor GetDateProperty = olkPA.UTCToLocalTime(olkPA.GetProperty(strPropName)) Set olkPA = Nothing End Function 

这是因为你正在返回一个string,如果可能的话,VBA将采用美国格式 – 也许使用

 Dim sTemp as string sTemp = GetLastVerb(msg) if isdate(stemp) then rng.Value = cdate(sTemp) else rng.value = sTemp end if