• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2325
  • Last Modified:

Get path and filename with VBA

Thank you very much for your help.

I need to import a csv file into a table. I would like the use VBA to open a dialog box where the user can point to the selected file to import. The code below opens a dialog box and allows the user to select a file and it puts the file name in the text box. But it doesn't include the full path. I need the full path for my next section of code to import the file.

How can I get the path with the file name?  


Dim objDialog As Object
 Set objDialog = Application.FileDialog(3)
With objDialog
    .AllowMultiSelect = False
    .Show
    If .SelectedItems.Count = 0 Then
        MsgBox "No file selected."
    Else
        Me.FileNameTextBox = Dir(.SelectedItems(1))
    End If
End With
Set objDialog = Nothing

Thanks
Bob
0
Rwardlow
Asked:
Rwardlow
1 Solution
 
mbizupCommented:
The Dir() function limits the output to just the filename.

For the full path, simply drop the dir():

Me.FileNameTextBox = .SelectedItems(1)

Open in new window

0
 
Rey Obrero (Capricorn1)Commented:
add another textbox for full path


Me.FilePathTextbox = .SelectedItems(1)
0
 
RwardlowAuthor Commented:
Excellent, thank you very much.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now