2
這有點奇怪,在過去的幾天裏我一直在努力。將VBA從Outlook導出到Excel的日期格式更改爲
我一直在更新一個在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
你是一個明星 - 它的工作原理:) –