「VBSでメール件数カウント」の続きなのですが、
「受信フォルダ」の下にサブフォルダがあった場合の、
件数カウントはどうすればよいでしょうか?
試しに作ってみましたのですが、自信がないので、
よろしければ診ていただけないでしょうか?
------------------------------------------------------------
Private Function Cnt_MailItem
Cnt_MailItem = 0
Set oApp = CreateObject("Outlook.Application")
Set oNs = oApp.GetNameSpace("MAPI")
Set oFol = oNs.GetDefaultFolder(6) '受信アイテイム
Cnt_MailItem = oFol.Items.Count
'サブフォルダカウント
Cnt_MailItem = Cnt_MailItem + Cnt_SubFol(oFol)
msgbox "メール数:" & Cnt_MailItem
End Function
'サブカウント
Private Function Cnt_SubFol(byVal pFol )
'サブがない場合は数えない
If pFol.Folders.Count <= 0 Then
Exit Function
End If
For i = 1 To pFol.Folders.Count
Set oItems = pFol.Folders.Item(i)
Cnt_SubFol = Cnt_SubFol + oItems.Items.Count + Cnt_SubFol(oItems)
next
Set oItems = Nothing
End Function
------------------------------------------------------------
よろしくお願い致します。
お礼
なるほど!! 確認してみます。 アドバイスありがとうございます。