Solved

Get path and filename with VBA

Posted on 2013-10-29
3
1,913 Views
Last Modified: 2013-10-29
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
Comment
Question by:Rwardlow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39609986
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
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39609991
add another textbox for full path


Me.FilePathTextbox = .SelectedItems(1)
0
 
LVL 1

Author Closing Comment

by:Rwardlow
ID: 39610030
Excellent, thank you very much.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question