I have this code that creates a series of folders under the currently selected folder:
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
What I am trying to do is add a subfolder called Proposal to be created under the "REQs and POs" folder.
This is being used to create folders on a public folder. I have never done coding in VBA before and cant for the life of me figure out how to add the subfolder.
I have been looking around online but can't find anything.
Any help would be greatly appreciated.
答案 0 :(得分: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