Solved

Folder Location Dialog Box

Posted on 2006-07-10
3
239 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Find out how to use dynamic social media in email signatures with this top 10 DOs & DON’Ts.
Use email signature images to promote corporate certifications and industry awards.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now