FileDialog(msoFileDialogFolderPicker) not using the current direct

N

nx3

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
 
N

nx3

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top