Share via

Default Directory

Anonymous
2010-06-25T12:54:24+00:00

When using Application.GetOpenFilename or Application.GetSaveAsFilename methods is it possible to define the default directory (and / or sub-directory) to be initially displayed in the dialog?


Thanks, I'm confused

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2010-06-25T15:39:18+00:00

I am retired several years now, so I don't have access to a network system to test this, but the documentation I have read seems to indicate this code will work for local and network drives, but you will have to test that for yourself. The code makes use of a function that returns the drive letter or network drive designation. This is the function...

Function GetDriveLetter(Path As String) As String

  Dim FS As Object, Drv As Object

  Set FS = CreateObject("Scripting.FileSystemObject")

  Set Drv = FS.GetDrive(FS.GetDriveName(Path))

  GetDriveLetter = Drv.DriveLetter

End Function

and here is the code (it replaces my previously posted code) that does all the work, calling the above function as needed...

Dim OldDir As String, OldDrive As String, DefaultPath As String

DefaultPath = "D:\Original Files\Documentation\ENG"

OldDrive = GetDriveLetter(CurDir)

OldDir = CurDir

ChDrive GetDriveLetter(DefaultPath)

ChDir DefaultPath

Application.GetOpenFilename

ChDrive OldDrive

ChDir OldDir

Was this answer helpful?

0 comments No comments

Answer accepted by question author

Anonymous
2010-06-25T14:57:14+00:00

Here is some code to handle the drive changing coupled with the code I posted earlier (all you have to do is set the DefaultPath variable to the path you want the dialog box to open at)...

Dim OldDir As String, OldDrive As String, DefaultPath As String

OldDir = CurDir

OldDrive = Left(CurDir, 1)

DefaultPath = "D:\Original Files\Documentation\ENG"

ChDrive Left(DefaultPath, 1)

ChDir "D:\Original Files\Documentation\ENG"

Application.GetOpenFilename

ChDrive OldDrive

ChDir OldDir

May I suggest you mark this (or my previous post) as the Answer... that way other volunteers in this forum won't have to open this thread to see that you no longer require assistence.

Was this answer helpful?

0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Anonymous
    2010-06-25T14:43:43+00:00

    Sorry, being thick! All sorted as i needed to change the drive first. Thanks for piointing me in the right direction.


    Thanks, I'm confused

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-06-25T14:41:13+00:00

    Hi Rick

    I have used the code as per your example but it does appear to be working as the dialog is not opening with the desired directory.

    Dim OldDir As String

    OldDir = CurDir

    ChDir "c:\tmp"

    Application.GetOpenFilename

    ChDir OldDir


    Thanks, I'm confused

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-06-25T13:11:37+00:00

    You can use VB's ChDir (change directory) function to control the directory/subdirectory those open in. For example...

    ChDir "C:\Users\Rick\Pictures\From Scanner\JPEGs"

    Application.GetOpenFilename

    will open in the indicated directory... just change the path in the ChDir statement to the path you want. Maybe to leave things as they are, you might consider doing it this way...

    OldDir = CurDir

    ChDir "C:\Users\Rick\Pictures\From Scanner\JPEGs"

    Application.GetOpenFilename

    ChDir OldDir

    Was this answer helpful?

    0 comments No comments