【问题标题】:Outlook 2007 Multi Select foldersOutlook 2007 多选文件夹
【发布时间】:2013-03-28 02:48:30
【问题描述】:

第一次问题:D。

我一直在为 Outlook 2007 编写一个 Marco,让用户选择一个文件夹,然后使用该文件夹将所有邮件项目移出它并将其移动到个人 Arhcive 文件夹,其中使用所选文件夹名称作为目标个人文件夹。

例如

用户选择一个名为“Test”的随机文件夹

marco 会预先映射到个人文件夹,然后它会找到具有相同名称的子文件夹并移动邮件项目。

我的问题:

我目前正在使用 '.PickFolder' 语法来选择文件夹,我要做的是有一个多选文件夹表单:

  • 我将如何使用组合框和列表框表单让所有 fodler 的 Mapi 出现在自定义表单中。

我知道这只会在一个级别上,但这就是我所需要的,因为 200 多个文件夹都在一个级别上。

正如代码一样,它一次可以与一个文件夹一起出色地工作,但我希望提高反.

谢谢你。

【问题讨论】:

    标签: vba outlook


    【解决方案1】:

    我已经解决了获取完整文件夹列表的问题(代码如下),但如果您需要更多关于其他部分的帮助,请添加评论,我将扩展我的答案。

    我不明白你会用 ComboBox 做什么。所以对于这个例子,我创建了一个表单并添加了一个 ListBox(称为ListBox1)。下面的代码将使用从选定文件夹向下的所有文件夹的名称填充列表框。请阅读 cmets 以了解您还能做什么(例如,通过子文件夹递归 - 我知道在这种情况下不需要这样做)。

    如果您需要更多帮助或信息,请告诉我。

    Private Sub PopulateListBoxWithFolders()
    
        Dim objApp As Outlook.Application
        Dim objNamespace As Outlook.NameSpace
        Dim objFolder As Outlook.MAPIFolder
    
        ' Clear current contents of listbox
        ListBox1.Clear
    
        Set objApp = New Outlook.Application
    
        Set objNamespace = objApp.GetNamespace("MAPI")
    
        ' Allow user to select folder.
        ' Replace this with either objNamespace.GetDefaultFolder(...) or objNamespace.GetFolderFromID(...)
        ' to avoid the user having to select a folder
        Set objFolder = objNamespace.PickFolder
    
        ' See if the user cancelled or no folder found
        If Not objFolder Is Nothing Then
            ' Addition of true here recurses through all subfolders
            ProcessFolder objFolder ', True
        End If
    
    End Sub
    
    ' Populates the ListBox with the folders. Optionally you can recurse all folders
    Sub ProcessFolder(objStartFolder As Outlook.MAPIFolder, Optional blnRecurseSubFolders As Boolean = False, Optional strFolderPath As String = "")
    
        Dim objFolder As Outlook.MAPIFolder
    
        Dim i As Long
    
         ' Loop through the items in the current folder
        For i = 1 To objStartFolder.Folders.Count
    
            Set objFolder = objStartFolder.Folders(i)
    
            ' Populate the listbox
            ListBox1.AddItem ListBox1.Text + objFolder.FolderPath
    
            If blnRecurseSubFolders Then
                ' Recurse through subfolders
                ProcessFolder objFolder, True, strFolderPath + "\" + objFolder.FolderPath
            End If
        Next
    
    End Sub
    

    如果您需要代码来识别多选 ListBox 中的选定项目,这里就是。要使 ListBox 多选,您应该将表单编辑器中的 MultiSelect 属性设置为 1 - fmMultiSelectMulti

    Private Sub btnOK_Click()
        Dim i As Long
    
        ' Loop through all items in the listbox identifying those that are selected
        With ListBox1
            For i = 0 To .ListCount - 1
                If .Selected(i) Then
                    ' Here goes the code to act on the selected item
                    ' In the example below it outputs to the Immediate window
                    Debug.Print .List(i)
                End If
            Next i
        End With
    
    End Sub
    

    【讨论】:

    • 谢谢吉姆,我会试一试的。我不太擅长创建 USERFORM,但我会尝试让它发挥作用。
    猜你喜欢
    • 1970-01-01
    • 2016-11-02
    • 2018-11-08
    • 1970-01-01
    • 2014-11-18
    • 1970-01-01
    • 2010-09-26
    • 1970-01-01
    • 2017-09-22
    相关资源
    最近更新 更多