• List files from Folder (Excel 2002 (xp) SP2)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » List files from Folder (Excel 2002 (xp) SP2)

    Author
    Topic
    #402976

    hey gang–

    I am writing a routine to import data from a text file into a template. I would like to invoke the Open dialog box (or something similar) to give my users a navigable interface. However, instead of opening the file they select, I need to be able to capture the name and path of the file to include in my import procedure. Would anyone have any suggestions on this.

    Viewing 3 reply threads
    Author
    Replies
    • #806392

      Look up the GetOpenFilename method of the Application object. It will let the user select a file, but it won’t open that file, just make the selected file name and path available.

    • #806393

      Look up the GetOpenFilename method of the Application object. It will let the user select a file, but it won’t open that file, just make the selected file name and path available.

    • #806396

      Here is some sample code I use:

      Sub GetOpenFileNameExample2()
          Dim vFilename As Variant
          Dim sPath As String
          Dim lFilecount As Long
          Dim lCount As Long
          sPath = "c:windowstemp"
          ChDrive sPath
          ChDir sPath
          vFilename = Application.GetOpenFilename("text files (*.txt),*.txt", _
      , "Please select the file(s) to import", , True)
          If TypeName(vFilename) = "Boolean" Then Exit Sub
          For lCount = 1 To UBound(vFilename)
          MsgBox vFilename(lCount)
          Next
      End Sub
      
      • #806412

        Thanks Hans and Jan for the input. I will try to implement your suggestions this afternoon.

      • #806414

        Thanks Hans and Jan for the input. I will try to implement your suggestions this afternoon.

      • #806479

        Quick followup question: for the FileFilter argument, is it possible to specify only files with no extention? The file to be imported is actually an export from an AS400 system. By default, these files are exported without extentions. If need be, I can get an RPG programmer to make a change to include an extention on the exported file, but thought I’d try this route first.

        (Yes, it would be easier and far more effiecient to query the AS400 directly, but my boss won’t let me do it that way– DON’T GET ME STARTED!!)

        • #806507

          I think the best you can do is to omit the FileFilter argument. This will make GetOpenFileName display ALL files, including those without extension. The old DOS notation *. to specify files without extension doesn’t work.

          • #806509

            I thought so, but it couldn’t hurt to ask. Thanks again.

          • #806510

            I thought so, but it couldn’t hurt to ask. Thanks again.

        • #806508

          I think the best you can do is to omit the FileFilter argument. This will make GetOpenFileName display ALL files, including those without extension. The old DOS notation *. to specify files without extension doesn’t work.

      • #806480

        Quick followup question: for the FileFilter argument, is it possible to specify only files with no extention? The file to be imported is actually an export from an AS400 system. By default, these files are exported without extentions. If need be, I can get an RPG programmer to make a change to include an extention on the exported file, but thought I’d try this route first.

        (Yes, it would be easier and far more effiecient to query the AS400 directly, but my boss won’t let me do it that way– DON’T GET ME STARTED!!)

    • #806397

      Here is some sample code I use:

      Sub GetOpenFileNameExample2()
          Dim vFilename As Variant
          Dim sPath As String
          Dim lFilecount As Long
          Dim lCount As Long
          sPath = "c:windowstemp"
          ChDrive sPath
          ChDir sPath
          vFilename = Application.GetOpenFilename("text files (*.txt),*.txt", _
      , "Please select the file(s) to import", , True)
          If TypeName(vFilename) = "Boolean" Then Exit Sub
          For lCount = 1 To UBound(vFilename)
          MsgBox vFilename(lCount)
          Next
      End Sub
      
    Viewing 3 reply threads
    Reply To: List files from Folder (Excel 2002 (xp) SP2)

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

    Your information: