Selecting folder with msoFileDialogFolderPicker

Status
Not open for further replies.

Izbi

New Member
Outlook version
Outlook 2007
Email Account
This macro saves selected emails into a folder chosen by function "BrowseForFolder". It also adds the date as part of the filename. My issue is that the default start folder selected is always the same and I have to navigate to the folder each time.
I want to use "msoFileDialogFolderPicker" to select the folder because this is able to remember the last folder chosen and default to that path as the start when the macro is called again.

Code:
Option Explicit

Public Sub Save_Messages_Select_Ask2()

Dim oMail As Outlook.MailItem
Dim objItem As Object
Dim sPath As String
Dim dtDate As Date
Dim sName As String
Dim enviro As String

enviro = CStr(Environ("USERPROFILE"))
For Each objItem In ActiveExplorer.Selection

If objItem.MessageClass = "IPM.Note" Then
Set oMail = objItem

sName = oMail.Subject

dtDate = oMail.ReceivedTime
sName = Format(dtDate, "yyyy mm dd", vbUseSystemDayOfWeek, _
vbUseSystem) & Format(dtDate, " hhnn", _
vbUseSystemDayOfWeek, vbUseSystem) & " - " & sName & ".msg"

sPath = BrowseForFolder(enviro & "\Documents\")
Debug.Print sPath & "\" & sName
oMail.SaveAs sPath & "\" & sName, olMSG

End If
Next

End Sub

Function BrowseForFolder(Optional OpenAt As Variant) As Variant

Dim ShellApp As Object
Set ShellApp = CreateObject("Shell.Application"). _
BrowseForFolder(0, "Please choose a folder", 0, OpenAt)

On Error Resume Next
BrowseForFolder = ShellApp.self.Path
On Error GoTo 0

Set ShellApp = Nothing
Select Case Mid(BrowseForFolder, 2, 1)
Case Is = ":"
If Left(BrowseForFolder, 1) = ":" Then GoTo Invalid
Case Is = "\"
If Not Left(BrowseForFolder, 1) = "\" Then GoTo Invalid
Case Else
GoTo Invalid
End Select

Exit Function

Invalid:
BrowseForFolder = False

End Function
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
K Selecting a folder from an entry in a Listbox Outlook VBA and Custom Forms 1
M Outllook vba - selecting a folder Using Outlook 1
S Unable to go to Inbox/Contacts Folder after selecting Public Folders. Using Outlook 1
N Selecting multiple calendar items Using Outlook 4
S Automatically selecting folders and deleting messages in Outlook VBA Outlook VBA and Custom Forms 7
S Creating Email - Selecting Pre-Defined Text Using Outlook 2
S Selecting "Mileage" field on "Detail" page Outlook VBA and Custom Forms 2
P Selecting specific calendar from Excel Outlook VBA and Custom Forms 5
RalphG101 No indication of attachment, when selecting file, send to outlook. Using Outlook 0
A Auto Insert of filename when selecting 'Remove Attachment' Using Outlook 1
R VBScript Sendmail not selecting correct 'from' address Outlook VBA and Custom Forms 3
230Grains iCloud COM Module Keeps de-selecting in Outlook 2013 Using Outlook 1
F Automatically close email after selecting mark unread Using Outlook 1
S categories are being cut off after selecting from category pop up form Using Outlook 3
S Outlook Custom form - selecting text in read page Using Outlook 0
V Selecting multiple folders Using Outlook 2
D Selecting shared calendar for appointment/meeting templates Using Outlook 2
B MS Office 2010: Word email merge not selecting default Outlook account Using Outlook 1
C Selecting days in business notes BCM (Business Contact Manager) 0
A Pull mail without marking and processing, only by selecting it Using Outlook 1
T Distribution Lists, Selecting members, filtering members out of the selection process (not one by one) Using Outlook 2
S E-mail contact Prompts when selecting TO: Using Outlook 2
T selecting and view multiple emails Using Outlook 2
G Selecting contacts from Groups within the Address Book Using Outlook 2
C Selecting calendar causes problems Using Outlook 2
J In Outlook 2010 selecting the Junk drop down for a message & then "Never block..." fails to add entr Using Outlook 7
C after selecting 'reply' font size is VERY small Using Outlook 2
A Selecting multiple folders within pst files? Using Outlook 2
S List Box - Selecting Multiple Items (Saving) Outlook VBA and Custom Forms 2
J Moved many emails to Outlook external folder, need to delete on Gmail server Using Outlook 13
A Going to folder using shortcuts Using Outlook 3
B Outlook 2016 Auto-archive creates new folder Using Outlook 4
B BCC issues after changing root folder path for gmail Using Outlook 1
Fozzie Bear Outlook 2016 Creating a shared local Contacts folder Using Outlook 2
A Cannot copy this folder because it may contain private items Using Outlook 0
A Unable to save recurring Meeting to Documents folder due to error Using Outlook 2
B Extracting email addresses from a folder - how to also get the name of the person the address is for? Using Outlook 5
E How to display "Change Folder" in Change Default Email Delivery Location in Exchange Outlook 2016 Using Outlook 1
J Moving Imported folder Using Outlook 2
R List folders in a combo box + select folder + move emails from inbox to that folder + reply to that email Outlook VBA and Custom Forms 1
J Sent Items Folder NOT Showing Correct From Email Address Using Outlook 0
B VBA to Collapse Task Folder Groups Outlook VBA and Custom Forms 1
Retired Geek Junk Folder Clean Up Rules Exchange Server Administration 1
D Outlook 2016 Deleting emails without affecting folder structure - Outlook Office 365 Using Outlook 3
B Outlook 365 - Folder pane list clears Using Outlook 24
P Add, remove, & reorder folder pane Using Outlook 6
R Folder pane width change Using Outlook 45
T Missing Folder in Outlook.com Using Outlook 3
R Setup autofoward rule on a particular folder in Outlook Using Outlook 0
T After I send a new email, it remains in the Draft folder Using Outlook.com accounts in Outlook 3
Similar threads


















































Top