-
Userform to File Emails
Good afternoon all,
I am trying to create a userform to file emails in my inbox to folders , the userfrom has 2 drop downs, 1st called folder, 2nd called subfolder, I then want to press file and the email goes to the selected subfolder.
I have sucessfully created the userform and populated the comboboxes and know how to move emails using a macro just dont know how to combine the 2.
All help greatly appricated.
TIA,
OT
-
Assuming the first folder is a sub folder of Inbox then you need something like the following which will set the folder according to whether the combo boxes have selected values. If no folders are selected the folder is set to the Inbox
Code:
Dim sFolder1 As String
Dim sFolder2 As String
Dim olFolder As Folder
If ComboBox1.ListIndex > -1 Then
sFolder1 = ComboBox1.Text
Else
sFolder2 = ""
End If
If ComboBox2.ListIndex > -1 Then
sFolder2 = ComboBox2.Text
Else
sFolder2 = ""
End If
Select Case True
Case Is = sFolder1 = "": Set olFolder = Session.GetDefaultFolder(olFolderInbox)
Case Is = sFolder2 = "": Set olFolder = Session.GetDefaultFolder(olFolderInbox).folders(sFolder1)
Case Else: Set olFolder = Session.GetDefaultFolder(olFolderInbox).folders(sFolder1).folders(sFolder2)
End Select