Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Jan 2005
    Location
    Gwent, Wales
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Setting Default Path (Excel 2002)

    Hi,

    I have a dialog box that opens and displays the folder structure etc when a user clicks a button. I'm trying to get this to always open in the same location "D:Test", as the users files will be stored here. I've tried to do this with chdir, this worked once but now does not. the code is below, can anyone help?

    Dim spath As String
    Dim fd As FileDialog
    Dim FFs As FileDialogFilters
    Dim strFilename As String

    spath = "D:Test"
    ChDrive spath
    ChDir spath


    Set fd = Application.FileDialog(msoFileDialogOpen)
    fd.AllowMultiSelect = False

    With fd
    Set FFs = .Filters
    With FFs
    .Clear
    .Add "Excel Files", "*.xls"
    End With


    If .Show = False Then Exit Sub

    strFilename = fd.SelectedItems(1)
    Workbooks.Open FileName:=strFilename

    End With

    ThisWorkbook.Close

    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Setting Default Path (Excel 2002)

    You can set the path as follows instead of using ChDrive and ChDir:

    Set fd = Application.FileDialog(msoFileDialogOpen)
    With fd
    .AllowMultiSelect = False
    .InitialFileName = "D:Test"
    Set FFs = .Filters
    ...
    ...
    End With

  3. #3
    Lounger
    Join Date
    Jan 2005
    Location
    Gwent, Wales
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting Default Path (Excel 2002)

    Thanks, that work great.

Posting Permissions

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