Results 1 to 12 of 12
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I use this code to open a dialogbox to select a file:

    Dim Vfile
    Vfile = Application.GetOpenFilename

    now...

    i know the dir c:\miadir\ an in this dir are many file with diffrent exstention (.doc, .xls, .csv..)

    is possible to open a dialogbox from the dir in object and show only the file with .csv exstention?

    tks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You can specify a file filter:

    Vfile = Application.GetOpenFilename("Comma Separated Values (*.csv),*.csv")

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='800473' date='29-Oct-2009 09:03']You can specify a file filter:

    Vfile = Application.GetOpenFilename("Comma Separated Values (*.csv),*.csv")[/quote]

    yes ok...
    But to set the the dir where are stored the file

    i just know wath is the default dir...
    the dir is c:\miadir\

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    If all users have Excel 2002 or later, you can use

    Code:
    Dim strFilename As String
    With Application.FileDialog(msoFileDialogOpen)
      .Filters.Clear
      .Filters.Add "Comma Separated Values", "*.csv"
      .InitialFileName = "C:\Miadir\"
      If .Show Then
    	strFilename = .SelectedItems(1)
      End If
    End With

  5. #5
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='800475' date='29-Oct-2009 09:08']If all users have Excel 2002 or later, you can use

    Code:
    Dim strFilename As String
    With Application.FileDialog(msoFileDialogOpen)
      .Filters.Clear
      .Filters.Add "Comma Separated Values", "*.csv"
      .InitialFileName = "C:\Miadir\"
      If .Show Then
    	strFilename = .SelectedItems(1)
      End If
    End With
    [/quote]

    error here: msoFileDialogOpen

    i have excel 2000

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    FileDialog only works in Office XP and later.

    GetOpenFilename does not let you specify a folder, but you could do it like this:

    ' Make sure that C: is the active drive
    ChDrive "C:"
    ' Make Miadir the active folder
    ChDir "C:\Miadir"
    ' Show the Open dialog
    Vfile = Application.GetOpenFilename("Comma Separated Values (*.csv),*.csv")

  7. #7
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='800478' date='29-Oct-2009 09:30']FileDialog only works in Office XP and later.

    GetOpenFilename does not let you specify a folder, but you could do it like this:

    ' Make sure that C: is the active drive
    ChDrive "C:"
    ' Make Miadir the active folder
    ChDir "C:\Miadir"
    ' Show the Open dialog
    Vfile = Application.GetOpenFilename("Comma Separated Values (*.csv),*.csv")[/quote]

    the code work well! but really the dir is on a server dir....

    \\myserver\dir1\dir2\

    and dir2 is the dir to show the .csv file..

    sorry for mistake

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Place the following declaration at the top of the code module:

    Code:
    Public Declare Function SetCurrentDirectory _
      Lib "kernel32" Alias "SetCurrentDirectoryA" _
      (ByVal lpPathName As String) As Long
    You can now use

    Code:
    Dim Vfile
    SetCurrentDirectory "\\myserver\dir1\dir2\"
    Vfile = Application.GetOpenFilename("CSV files,*.csv")

  9. #9
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='800480' date='29-Oct-2009 10:02']Place the following declaration at the top of the code module:

    Code:
    Public Declare Function SetCurrentDirectory _
      Lib "kernel32" Alias "SetCurrentDirectoryA" _
      (ByVal lpPathName As String) As Long
    You can now use

    Code:
    Dim Vfile
    SetCurrentDirectory "\\myserver\dir1\dir2\"
    Vfile = Application.GetOpenFilename("CSV files,*.csv")
    [/quote]

    work perfect!

  10. #10
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='800478' date='29-Oct-2009 09:30']FileDialog only works in Office XP and later.

    GetOpenFilename does not let you specify a folder, but you could do it like this:

    ' Make sure that C: is the active drive
    ChDrive "C:"
    ' Make Miadir the active folder
    ChDir "C:\Miadir"
    ' Show the Open dialog
    Vfile = Application.GetOpenFilename("Comma Separated Values (*.csv),*.csv")[/quote]


    HI hANS...
    I have see (in the code forr excel 2002 - you have used strFilename = .SelectedItems(1) ) is possible to store the name of the file clicked how to with excel 2000???

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You can't use FileDialog in Excel 2000.
    The GetOpenFilename function returns the name of the selected file (or False if the user canceled the dialog).

  12. #12
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Slinky View Post
    Place the following declaration at the top of the code module:

    Code:
    Public Declare Function SetCurrentDirectory _
      Lib "kernel32" Alias "SetCurrentDirectoryA" _
      (ByVal lpPathName As String) As Long
    You can now use

    Code:
    Dim Vfile
    SetCurrentDirectory "\\myserver\dir1\dir2\"
    Vfile = Application.GetOpenFilename("CSV files,*.csv")
    ... but instead to open dialogbox, i know the name of file, how to set Vfile?

Posting Permissions

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