本文介绍了无法设置子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Outlook VBA的新手,并且很难弄清楚如何在下面的代码中设置子文件夹.我整天都在拍摄时遇到麻烦.不知道我在想什么.

I'm new to Outlook VBA and having a tough time figuring out how to set my subfolder in the code below. I have been trouble shooting this all day. Not sure what I'm missing.

Sub DeleteOlderThan6months()

Dim oFolder As Folder
Dim Date6months As Date
Dim ItemsOverMonths As Outlook.Items

Dim DateToCheck As String

Date6months = DateAdd("d", -1, Now())
Date6months = Format(Date6months, "mm/dd/yyyy")


Set oFolder = oFolder.Folders("[email protected]").Folders("Inbox").Folders("Zip Files")

DateToCheck = "[Received] <= """ & Date6months & """"

Set ItemsOverMonths = oFolder.Items.Restrict(DateToCheck)

For i = ItemsOverMonths.Count To 1 Step -1
ItemsOverMonths.Item(i).Delete
Next


Set ItemsOverMonths = Nothing
Set oFolder = Nothing


End Sub

推荐答案

这应该做到,看看我如何设置子文件夹

This should do it, see how i set the subfolder

Option Explicit
Sub DeleteOlderThan6months()
    '//  Declare variables
    Dim oFolder As Folder
    Dim Date6months As Date
    Dim ItemsOverMonths As Outlook.Items
    Dim DateToCheck As String
    Dim olNs As Outlook.NameSpace
    Dim Inbox  As Outlook.MAPIFolder
    Dim oItem As Object
    Dim i As Long

    '// set your inbox and subfolder
    Set olNs = Application.GetNamespace("MAPI")
    Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
    Set oFolder = Inbox.Folders("Zip Files")

    Date6months = DateAdd("d", -1, Now())
    Date6months = Format(Date6months, "mm/dd/yyyy")

    DateToCheck = "[Received] <= """ & Date6months & """"
    Set ItemsOverMonths = oFolder.Items.Restrict(DateToCheck)

    '// Loop through the Items in the folder backwards
    For i = ItemsOverMonths.Count To 1 Step -1
        Set oItem = ItemsOverMonths.Item(i)
        If TypeOf oItem Is Outlook.MailItem Then
            Debug.Print oItem.Subject
            oItem.Delete
        End If
    Next

    Set ItemsOverMonths = Nothing
    Set oFolder = Nothing

End Sub

这篇关于无法设置子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-22 02:43