2013-03-28 68 views
1

第一次問題:D。Outlook 2007多選文件夾

我一直在編寫一個Marco for Outlook 2007,讓用戶選擇一個文件夾,然後用該文件夾將所有郵件移出並將其移動到個人Arhcive文件夾,其中使用所選文件夾名稱作爲目的地在個人文件夾下。

例如

用戶選擇與療法名稱「測試」一randon文件夾

馬可將事先映射到個人文件夾,然後它會查找具有相同名稱的子文件夾和移動郵件。

我的問題:

我目前正在使用'。 PickFolder'語法有使用選擇的文件夾,我做的是有一個多選文件夾構成:

  • 我怎麼會去讓所有的fodlers的馬屁出現在自定義窗體使用Combobox和列表框表單。

我知道這隻會在一個級別,但這是我所需要的,因爲200 +文件夾都在一個級別。

由於代碼是,它一次出色地與一個文件夾,但我希望了反。

Thnak you。

回答

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的多選你應該在表格編輯器中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 
+0

感謝吉姆,我給這個一展身手。我不擅長創建用戶界面,但我會嘗試使其工作。 – 2013-04-03 01:54:10