![](/img/trans.png)
[英]Parsing Excel sheet based on date, number of visitors, and printing email
[英]Save date and time of emails into Excel sheet based on email id for last 30 days
這是我的代碼,我對過濾日期感到震驚。 我需要保存User(harshahowrang@gmail.com)
電子郵件的日期和時間信息,從現在開始的最后 30 天。 必須在 Excel 工作表中保存該信息(時間和日期)
Set ObjO = CreateObject("Outlook.Application")
Set olNs = ObjO.GetNamespace("MAPI")
Set objFolder = olNs.GetDefaultFolder(6)
For Each item1 In objFolder.Items
Dim sa, bc
bc = item1.ReceivedTime
sa = Format(item1.ReceivedTime, "dd-MM-yyyy")
spa = "27/02/2018"
If item1.UnRead And item1.SenderEmailAddress = "harshahowrang@gmail.com" And sa < spa Then
我可以使用 Item1 對象獲取日期和時間,但對我來說具有挑戰性的部分是獲取從今天開始的最后 30 天的信息。
它不應超過 1 個月.. 所以每個月我都需要生成這個宏來給出特定用戶電子郵件的日期和時間,並將該信息保存在 excel 表中。
這是我每個月手動進行的月度活動
一種低效的方法,不是先按適用的時間段限制物品。
Private Sub findByDate()
Dim ObjO As Object
Dim olNs As Object
Dim objFolder As Object
Dim item1 As Object
Dim sa As Date
Dim spa As Date
Set ObjO = CreateObject("Outlook.Application")
Set olNs = ObjO.GetNamespace("MAPI")
Set objFolder = olNs.GetDefaultFolder(6)
Set objFolder = olNs.GetDefaultFolder(6)
Debug.Print objFolder
spa = "27/02/2018"
Debug.Print "Oldest date.....: " & spa - 30
Debug.Print "Most recent date: " & spa
For Each item1 In objFolder.Items
sa = Format(item1.ReceivedTime, "dd-MM-yyyy")
If sa <= spa Then
If sa > spa - 30 Then
Debug.Print item1.ReceivedTime & " - " & item1.Subject
End If
End If
Next
Set ObjO = Nothing
Set olNs = Nothing
Set objFolder = Nothing
End Sub
當前,您的變量sa和spa被視為字符串。您必須將它們聲明為日期才能進行日期比較。
dim sa as date
dim bc as date
dim spa as date
With niton example 這是另一個例子 Filter for 30 days
Dim DateDiff As Long
DateDiff = Now - 30
Dim Filter As String
Filter = "[SentOn] < '" & Month(DateDiff) & "/" & _
Day(DateDiff) & "/" & _
Year(DateDiff) & "'"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.