Solved

Folder Location Dialog Box

Posted on 2006-07-10
3
259 Views
Last Modified: 2010-04-08
i'm looking to have a browse button so a folder can be selected for both saving a file and another to open a file. As there are many files to open, i just need the folder location not the file location. How do i activate the dialog box as most code i've seen in excel and other vb doesn't work in outlook?
0
Comment
Question by:james_daley
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 17078553
Hi james_daley,

Try this.  Usage is:

    strSelectedFolderPath = BrowseForFolder()

The value returned will either be a complete folder path or the string "User cancelled".  This works great with Office 2003.  Not sure about previous versions of Office.  It uses the FileDialog object which is available in Word, Excel, and Access (and perhaps other Office apps), but was left out of Outlook.

Function BrowseForFolder() As String
    Dim objWord As Object, _
        objDialog As Object, _
        strPath As String
    Set objWord = CreateObject("Word.Application")
    Set objDialog = objWord.FileDialog(4)   '4 = msoFileDialogFolderPicker
    With objWord
        .Width = 0
        .Height = 0
        .WindowState = 2                              '2 = wdWindowStateMinimize
        If Not .Visible Then .Visible = True
    End With
    With objDialog
        .InitialView = 1                                  '1 =msoFileDialogViewList
        If .Show = -1 Then
            strPath = objDialog.SelectedItems(1) & "\"
        Else
            strPath = "User cancelled"
        End If
    End With
    objWord.Visible = False
    objWord.Quit False
    Set objDialog = Nothing
    Set objWord = Nothing
    BrowseForFolder = strPath
End Function


Cheers!
0
 
LVL 1

Author Comment

by:james_daley
ID: 17078998
Works very well thankyou! You wouldn't happen to know how to use the Windows API to browse for the folder would you?
0
 
LVL 1

Author Comment

by:james_daley
ID: 17079384
Not to worry, found some code that works as good as yours, thanks again.

P.S i also have another outlook question that's kinda needed asap so if ya not busy and want some easy points, jump in!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you don't know how to downgrade, my instructions below should be helpful.
In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question