none
get selected file name RRS feed

  • Question

  • Hi all, I have the following questions: 
    I have 2 variables of type string, the first I want to save the path of a selected file and the second only the name and extension, I am using Application.GetOpenFilename (), I hope you can help me, greetings
    Friday, October 17, 2014 4:59 PM

Answers

  • re:  some file properties

    Sub Test()
     Dim strPath As String
     Dim strName As String
     Dim FileToOpen As Variant
     
     FileToOpen = Application.GetOpenFilename("Text Files (*.txt), *.txt")
     If FileToOpen <> False Then
      strPath = FileToOpen
      strName = VBA.Right$(FileToOpen, VBA.Len(FileToOpen) - VBA.InStrRev(FileToOpen, _
                     Application.PathSeparator, -1, vbBinaryCompare))
     End If
     MsgBox strPath & vbCr & strName
    End Sub
    '---
    Jim Cone
    Portland, Oregon USA
    free & commercial excel programs
    https://goo.gl/IUQUN2 (Dropbox)

    • Marked as answer by aslf010990 Friday, October 17, 2014 8:06 PM
    • Edited by James Cone Tuesday, October 18, 2016 5:08 PM
    Friday, October 17, 2014 7:54 PM

All replies

  • re:  some file properties

    Sub Test()
     Dim strPath As String
     Dim strName As String
     Dim FileToOpen As Variant
     
     FileToOpen = Application.GetOpenFilename("Text Files (*.txt), *.txt")
     If FileToOpen <> False Then
      strPath = FileToOpen
      strName = VBA.Right$(FileToOpen, VBA.Len(FileToOpen) - VBA.InStrRev(FileToOpen, _
                     Application.PathSeparator, -1, vbBinaryCompare))
     End If
     MsgBox strPath & vbCr & strName
    End Sub
    '---
    Jim Cone
    Portland, Oregon USA
    free & commercial excel programs
    https://goo.gl/IUQUN2 (Dropbox)

    • Marked as answer by aslf010990 Friday, October 17, 2014 8:06 PM
    • Edited by James Cone Tuesday, October 18, 2016 5:08 PM
    Friday, October 17, 2014 7:54 PM
  • Thanks , I resolved my problem , Greetings
    Friday, October 17, 2014 8:06 PM