Question

Chris32135 on Mon, 14 Aug 2017 00:35:34


So I am working on a project to retrieve attachments from outlook, then import the contents of said attachment into excel.  To make the code more robust, I thought it would be good to allow them to select the folder to search incase they store the emails into a different folder. Any ideas on how to do this?

Thank you,

Chris


Sponsored



Replies

Kareninstructor on Mon, 14 Aug 2017 18:56:09


See my reply below which has a link describing how versions of Outlook can have different locations for emails and this is coupled with different versions of windows.

https://social.msdn.microsoft.com/Forums/en-US/c724e4b3-dbf1-41b8-9bec-dc3a8bddd907/location-of-outlook-pst-and-ost-files?forum=vbgeneral

Eugene Astafiev on Tue, 15 Aug 2017 10:30:28


Hello Chris,

Looks like you are interested in the PickFolder method of the Namespace class which displays the Pick Folder dialog box. The Pick Folder dialog box is a modal dialog box which means that code execution will not continue until the user either selects a folder or cancels the dialog box. The returned value is a Folder object that represents the folder that the user selects in the dialog box, or Nothing if the dialog box is canceled by the user. For example, a VBA macro sample code:

Sub FolderPick()

    Dim objNS As NameSpace
    Dim objFolder As folder

    Set objNS = Application.GetNamespace("MAPI")
    Set objFolder = objNS.PickFolder

    If TypeName(objFolder) <> "Nothing" Then
        Debug.Print vbCr & " objFolder: " & objFolder
    Else
        Debug.Print vbCr & "Cancel"
    End If

    Set objFolder = Nothing
    Set objNS = Nothing

End Sub

Celeste Li on Fri, 25 Aug 2017 03:27:27


Hello Chris,

Does code shared by Eugene work for you?

If your issue persists, please free feel to let me know.

Regards,

Celeste