Selecting folder with msoFileDialogFolderPicker

Status
Not open for further replies.

mail11

Senior Member
Outlook version
Email Account
IMAP
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.
Similar threads
Thread starter Title Forum Replies Date
M Saving emails using Visual Basic - Selecting folder with msoFileDialogFolderPicker Outlook VBA and Custom Forms 6
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
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
S List Box - Selecting Multiple Items (Saving) Outlook VBA and Custom Forms 2
V Folder Properties - Gmail account can't switch Using Outlook 5
Victor_50 Outlook 2019 Jump to folder from search folder Outlook VBA and Custom Forms 0
HarvMan Outlook 365 - Rule to Move an Incoming Message to Another Folder Using Outlook 4
S Email Macros to go to a SHARED Outlook mailbox Draft folder...NOT my personal Outlook Draft folder Using Outlook 2
I Help with Smart Folder + Query Builder on IMAP Using Outlook 0
S Paperclip icon shows without attachment in email under Sent folder Using Outlook 0
Kika Melo Outlook Calendar deleted appointments not in Deleted Items folder Using Outlook 3
K vba code to auto download email into a specific folder in local hard disk as and when any new email arrives in Inbox/subfolder Outlook VBA and Custom Forms 0
Z Outlook 365 Automatically assign categories to incoming mail in a shared folder Round Robin Outlook VBA and Custom Forms 1
G Adding a contact to a specific folder Using Outlook 0
Witzker Outlook 2019 Macro GoTo user defined search folder Outlook VBA and Custom Forms 7
Rupert Dragwater Duplicate email in Folder Using Outlook 7
S Adding a recipient's column to Sent folder in Outlook 2010 Outlook VBA and Custom Forms 1
L "Insert Pictures" Button-Wrong Folder Using Outlook 5
C Outlook 365 Copy/Save Emails in Folder Outside Outlook to Show Date Sender Recipient Subject in Header Using Outlook 0
Christopher M Outlook 365 Hey Diane! MS 365 Biz Standard and "Potential Spam" addressed to others coming to my JUNK folder? Using Outlook 2
J Quick steps delete original email and move reply/sent email to folder Using Outlook 2
A manual rule sends mail to wrong folder Using Outlook 5
richardwing Auto forward email that is moves into a specific outlook folder Outlook VBA and Custom Forms 5
D This folder up to date vs all folders up to date Using Outlook 1
G Automatically delete messages in the synchronization folder Outlook VBA and Custom Forms 4
wayneame Changing the Form Used by Existing Task Items in a Folder Outlook VBA and Custom Forms 4
S Need code to allow defined starting folder and selection from there to drill down Outlook VBA and Custom Forms 10
P Emails assigned with a certain category (within a shared inbox) to be copied to a specific folder. Outlook VBA and Custom Forms 2
B Search and Find Email by Folder Name Outlook VBA and Custom Forms 2
S Folder Pane Colour Categories Using Outlook 6
Victor.Ayala Automated way to check the option "Show this folder as an email Address Book" Outlook VBA and Custom Forms 2
NVDon Create new Move To Folder list Outlook VBA and Custom Forms 0
M Extract "Date sent" from emails (saved to folder using drag and drop) Outlook VBA and Custom Forms 1

Similar threads

Top