Consulting

Results 1 to 5 of 5

Thread: VBA extracting file name and path HELP ::::

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    VBA extracting file name and path HELP ::::

    Need alot of help
    what's wrong with my code???? i need it to extract the file name and path it is taking data from
    im still new to VBA and no one in my office seems to be able to have the time to help me

    -----------------------------------------------------------

    Sub GetPartOfFilePath()
    Dim myPath As String
    Dim myOutput As String
    Dim originalFile As String
    Dim NewFile As String
    
    'Retrieve ActiveWorkbook's File Path (Displayed in Immediate Window [ctrl + g])
    originalFile = ActiveWorkbook.name
    NewFile = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls*), *.xls", Title:="Please select a file", MultiSelect:=False) 'only excel files
    Workbooks.Open NewFile
    NewFile = Dir(NewFile)
    
    'Retrieve File Name with Extension (Displayed in Immediate Window [ctrl + g])
    myOutput = Right(myPath, Len(myPath) - InStrRev(myPath, "\"))
    Debug.Print "File Name (w/ ext): " & myOutput
    
    End Sub
    End Sub
    Last edited by Bob Phillips; 05-03-2016 at 04:02 AM. Reason: Added code tags

Posting Permissions

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