Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

Folder Location Dialog Box

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
james_daley
Asked:
james_daley
  • 2
1 Solution
 
David LeeCommented:
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
 
james_daleyAuthor Commented:
Works very well thankyou! You wouldn't happen to know how to use the Windows API to browse for the folder would you?
0
 
james_daleyAuthor Commented:
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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now