2015-06-25 183 views
3

我有這樣的代碼創建當前選擇的文件夾下的一系列的文件夾:下創建Outlook 2010中創建文件夾和子文件夾

Public Sub CreateFolders() 
Dim CurrentFolder As Outlook.MAPIFolder 
Dim Subfolder As Outlook.MAPIFolder 
Dim List As New VBA.Collection 
Dim Folders As Outlook.Folders 
Dim Item As Variant 

List.Add Array("Audio Video Graphics", olFolderInbox) 
List.Add Array("Close Out", olFolderInbox) 
List.Add Array("Correspondence", olFolderInbox) 
List.Add Array("Expenditure Adjustments", olFolderInbox) 
List.Add Array("Invoices", olFolderInbox) 
List.Add Array("Project Schedule", olFolderInbox) 
List.Add Array("RADPARs and Contracts", olFolderInbox) 
List.Add Array("REQs and POs", olFolderInbox) 
List.Add Array("Technical Information", olFolderInbox) 

Set CurrentFolder = Application.ActiveExplorer.CurrentFolder 
Set Folders = CurrentFolder.Folders 
For Each Item In List 
    Folders.Add Item(0), Item(1) 
Next 
End Sub 

我所試圖做的是添加一個名爲提案子文件夾「 REQ和PO「文件夾。

這是用來在公用文件夾上創建文件夾。我從來沒有在VBA中編寫過代碼,而且我不知道如何添加子文件夾。

我一直在網上查找,但找不到任何東西。

任何幫助將不勝感激。

回答

3

試試這個。

Public Sub CreateFolders() 
Dim CurrentFolder As Outlook.MAPIFolder 
Dim Subfolder As Outlook.MAPIFolder 
Dim List As New VBA.Collection 
Dim Folders As Outlook.Folders 
Dim Item As Variant 

List.Add Array("Audio Video Graphics", olFolderInbox) 
List.Add Array("Close Out", olFolderInbox) 
List.Add Array("Correspondence", olFolderInbox) 
List.Add Array("Expenditure Adjustments", olFolderInbox) 
List.Add Array("Invoices", olFolderInbox) 
List.Add Array("Project Schedule", olFolderInbox) 
List.Add Array("RADPARs and Contracts", olFolderInbox) 
List.Add Array("REQs and POs", olFolderInbox) 
List.Add Array("Technical Information", olFolderInbox) 

Set CurrentFolder = Application.ActiveExplorer.CurrentFolder 
Set Folders = CurrentFolder.Folders 
For Each Item In List 
    Folders.Add Item(0), Item(1) 
Next 

Set Folders = CurrentFolder.Folders.Item("REQs and POs").Folders 

' or simply 
'Set Folders = CurrentFolder.Folders("REQs and POs").Folders 

Folders.Add "Proposal", olFolderInbox 

End Sub 
+0

工作完美。感謝您的幫助,我真的很感激。我一直在思考這個問題。 – topher