• open dialog box with only csv file

    Author
    Topic
    #463522

    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.

    Viewing 1 reply thread
    Author
    Replies
    • #1183552

      You can specify a file filter:

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

      • #1183553

        You can specify a file filter:

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

        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

    • #1183554

      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
      • #1183555

        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

        error here: msoFileDialogOpen

        i have excel 2000

        • #1183557

          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”)

          • #1183558

            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”)

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

            \myserverdir1dir2

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

            sorry for mistake

            • #1183559

              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 "\myserverdir1dir2"
              Vfile = Application.GetOpenFilename("CSV files,*.csv")
            • #1183560

              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 "\myserverdir1dir2"
              Vfile = Application.GetOpenFilename("CSV files,*.csv")

              work perfect!

            • #1208836

              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 "\myserverdir1dir2"
              Vfile = Application.GetOpenFilename("CSV files,*.csv")

              … but instead to open dialogbox, i know the name of file, how to set Vfile?

          • #1183587

            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”)

            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???

            • #1183590

              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).

    Viewing 1 reply thread
    Reply To: open dialog box with only csv file

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: