1

我已将 Outlook 电子邮件数据导出到 Excel。

现在,我遇到的另一个问题是 PR_LAST_VERB_EXECUTION_TIME 不显示为相同的日期格式。

日期可以是ddmmyyyy hh:mm:ss AM/PM 或 mmddyyyy hh:mm格式(请参考 img)。
我还确保所有单元格格式都是通用的。

是否可以标准化日期格式或可能有任何其他原因导致这种情况?
显示为不同的日期格式(ddmmyyyy hh:mm:ss AM/PM 或 mmddyyyy hh:mm)


我的代码如下:

For Each itm In Items
'Check item type
If TypeName(itm) = "MailItem" Then
intColumnCounter = 1
Set msg = itm
intRowCounter = intRowCounter + 1
Set rng = wks.Cells(intRowCounter, intColumnCounter)
rng.Value = GetLastVerb(msg)
End If
Next

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 = olkMsg.ReceivedTime
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.GetProperty(strPropName)
Set olkPA = Nothing
End Function


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
4

1 回答 1

1

背后的原因很简单

该函数GetLastVerb调用其他返回 aDate或 a 的函数,variant然后最终GetLastVerb返回一个字符串。最好的方法是在将输出写入范围之前简单地格式化输出

如果您不关心type最终输出,即它是字符串还是日期,则替换rng.Value = GetLastVerb(msg)rng.Value = Format(GetLastVerb(msg), "dd/mm/yyyy hh:mm:ss AM/PM")

如果您想要正确的日期输出,请将列格式化为相关的日期/时间格式,然后用于formula更新单元格

例如

Columns("A:A").NumberFormat = "dd/mm/yyyy hh:mm:ss AM/PM"

rng.FormulaR1C1 = Format(GetLastVerb(msg), "dd/mm/yyyy hh:mm:ss AM/PM")
于 2013-02-19T09:41:12.833 回答