1

第一次问题:D。

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

例如

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

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

我的问题:

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

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

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

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

谢谢你。

4

1 回答 1

1

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

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

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

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
于 2013-03-28T14:49:14.407 回答