View Single Post
 
Old 11-03-2014, 06:50 AM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,598
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

You just need a function to define your static strFolder:

Code:
Sub TestMethods()
  MsgBox fcnFolderPicker_msoFileDialogMethod("Select folder")
  MsgBox fcnShellBrowseForFolder
End Sub
Function fcnFolderPicker_msoFileDialogMethod(strTitle As String, Optional strInitialPath As String = "C:\", Optional bAllowMulti As Boolean = False) As String
Dim strPath As String
Dim fDialog As FileDialog
  Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
  With fDialog 'Pick folder containing the files
    .Title = strTitle
    .AllowMultiSelect = bAllowMulti
    .InitialView = msoFileDialogViewList
    .InitialFileName = strInitialPath
    If .Show <> -1 Then
      fcnFolderPicker_msoFileDialogMethod = "Nothing selected, cancelled by user"
    Exit Function
    End If
    strPath = fDialog.SelectedItems.Item(1)
    fcnFolderPicker_msoFileDialogMethod = strPath
  End With
lbl_Exit:
  Exit Function
End Function

Function fcnShellBrowseForFolder(Optional strTitle As String, Optional strRootFolder As Variant) As String
  On Error Resume Next
  fcnShellBrowseForFolder = CreateObject("Shell.Application").BrowseForFolder(0, strTitle, 0, strRootFolder).Items.Item.Path
  On Error GoTo 0
lbl_Exit:
  Exit Function
End Function
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote