+ Reply to Thread
Results 1 to 2 of 2

FileDialog(msoFileDialogFolderPicker) not using the current direct

  1. #1
    nx3
    Guest

    FileDialog(msoFileDialogFolderPicker) not using the current direct

    My code is below. Very simple, the users to select a directory and I'd like
    to pick up where this has been previously set. This all works, it picksup the
    directory, it changes the CurDir and msgbox it back all fine. Then the next
    stage is the file browse dialog and is using somewhere else again ! How can I
    set or control where the FileDialog(msoFileDialogFolderPicker) starts the
    default view from ?
    TIA

    Public OldDir As String
    Public ArchiveDir As String

    Sub UseFileDialogOpen()

    'Pick Up Current Directory
    OldDir = CurDir

    'Pick up archive directory
    ArchiveDir = Sheets("Files").Range("B9").Value
    'ArchiveDir = "C:\windows\"

    'Test Archive Directory exists
    If Dir(ArchiveDir, vbDirectory) <> "" Then
    'If ArchiveDir Found
    ChDir ArchiveDir
    MsgBox CurDir
    End If

    ' Open the file dialog
    Set BrowseFolder = Application.FileDialog(msoFileDialogFolderPicker)
    With BrowseFolder
    .Show
    If BrowseFolder.SelectedItems.Count > 0 Then
    Var = .SelectedItems(1)
    End If
    End With

    MsgBox Var

    End Sub

  2. #2
    nx3
    Guest

    RE: FileDialog(msoFileDialogFolderPicker) not using the current direct

    To answer my own question as I was being silly... I need to set
    ..InitialFileName as per below and it works

    ' Open the file dialog
    Set BrowseFolder = Application.FileDialog(msoFileDialogFolderPicker)
    With BrowseFolder
    .InitialFileName = ArchiveDir
    .Show
    If BrowseFolder.SelectedItems.Count > 0 Then
    Var = .SelectedItems(1)
    End If
    End With


    "nx3" wrote:

    > My code is below. Very simple, the users to select a directory and I'd like
    > to pick up where this has been previously set. This all works, it picksup the
    > directory, it changes the CurDir and msgbox it back all fine. Then the next
    > stage is the file browse dialog and is using somewhere else again ! How can I
    > set or control where the FileDialog(msoFileDialogFolderPicker) starts the
    > default view from ?
    > TIA
    >
    > Public OldDir As String
    > Public ArchiveDir As String
    >
    > Sub UseFileDialogOpen()
    >
    > 'Pick Up Current Directory
    > OldDir = CurDir
    >
    > 'Pick up archive directory
    > ArchiveDir = Sheets("Files").Range("B9").Value
    > 'ArchiveDir = "C:\windows\"
    >
    > 'Test Archive Directory exists
    > If Dir(ArchiveDir, vbDirectory) <> "" Then
    > 'If ArchiveDir Found
    > ChDir ArchiveDir
    > MsgBox CurDir
    > End If
    >
    > ' Open the file dialog
    > Set BrowseFolder = Application.FileDialog(msoFileDialogFolderPicker)
    > With BrowseFolder
    > .Show
    > If BrowseFolder.SelectedItems.Count > 0 Then
    > Var = .SelectedItems(1)
    > End If
    > End With
    >
    > MsgBox Var
    >
    > End Sub


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1