1 Reply Latest reply on Aug 9, 2013 6:31 AM by Deepak Gupta

    How to get the directory or path of selected file and redirect it to sFileName?

    Jinhong Chong

      Sub main()



      Dim Filter As String

      Dim fileName As String

      Dim fileConfig As String

      Dim fileDispName As String

      Dim fileOptions As Long

      Dim a As Variant

      ReDim a(0 To 100)


      Set swApp = Application.SldWorks

      Filter = "Distance value (*.txt; )|*.txt;*.txt;*.txt|Filter name (*.fil)|*.fil|All Files (*.*)|*.*|"

      fileName = swApp.GetOpenFileName("File to Attach", "", Filter, fileOptions, fileConfig, fileDispName)

      Debug.Print fileName



          Dim arr() As String

          Dim sFileName As String

          Dim iFileNum As Integer

          Dim sBuf As String


         sFileName = "C:\Users\hong\Desktop\msg.txt"


          If Len(Dir$(sFileName)) = 0 Then

              Exit Sub

          End If


          iFileNum = FreeFile()

          Open sFileName For Input As iFileNum


          Dim i As Integer

          i = -1

          Do While Not EOF(iFileNum)

              i = i + 1

              ReDim Preserve arr(i)

              Line Input #iFileNum, sBuf

              arr(i) = sBuf

              Debug.Print sBuf



          Close iFileNum

          MsgBox arr(1)



      End Sub