这是最近几天一直在想的一个奇怪的问题。
我一直在更新 Outlook 中的一个宏,它将详细信息导出到 Excel。
到目前为止,宏一直运行良好,可以顺利导出发件人、主题和发送和接收的日期。
我已经添加了一些内容,以便在电子邮件已被回复/转发时捕获时间和日期,但这就是问题所在。
运行代码时,如果我将 Debug.Print 放在保存回复/转发日期的变量上,它会以正确的格式 (dd/mm/yyyy hh:mm:ss) 打印出来,但是当它弹出一些因为它被输入为 mm/dd/yyyy hh:mm:ss(但仅适用于月份 <= 12 的日期)。
我检查了计算机的区域设置(实际上我已经在 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