Home > Mobile >  GetOpenFilename Default Location to Downloads
GetOpenFilename Default Location to Downloads

Time:08-27

I don't see any parameter in GetOpenFilename to set default folder to Downloads.

Currently, it opens Documents folder. Is it possible to make the default location as Downloads folder.

I can't hardcode the path as Downloads without including the Username. e.g C:\Users\NameOfUser\Downloads

CodePudding user response:

Choose Files to Open (FileDialog)

Sub ChooseFilesToOpen()
    
    Dim iFolderPath As String: iFolderPath = Environ("USERPROFILE") _
        & Application.PathSeparator & "Downloads" & Application.PathSeparator
    
    Dim FilePaths As FileDialogSelectedItems
    
    With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = True
        .Filters.Clear
        .Filters.Add "Excel Workbook", "*.xlsx"
        .InitialFileName = iFolderPath
    
        If .Show <> -1 Then
            MsgBox "Canceled.", vbExclamation
            Exit Sub
        End If
    
        Set FilePaths = .SelectedItems
    End With
    
    Dim FilePath As Variant
    
    For Each FilePath In FilePaths
        Debug.Print FilePath
    Next FilePath
    
End Sub
  • Related