Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have the following code.

VB
Dim fDialog As Office.FileDialog
   Dim varFile As Variant
   Dim Path As String
   ' Set up the File Dialog.
   Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
   With fDialog
      
       fDialog.AllowMultiSelect = False       
      fDialog.Title = "Please Select An Excel Sheet"
      Clear out the current filters, and add our own.
      fDialog.Filters.Clear
      fDialog.Filters.Add "Excel Sheets 2003", "*.xls"
      fDialog.Filters.Add "Excel Sheets 2007", "*.xlsx"
      '.Filters.Add "All Files", "*.*"
      ' Show the dialog box. If the .Show method returns True, the
      ' user picked at least one file. If the .Show method returns
      ' False, the user clicked Cancel.
      If fDialog.Show = True Then
       Path = fDialog.InitialFileName
      'Importing the Data From Excel Sheet to access database


Path = fDialog.InitialFileName : In this statement the path comes until the last folder that contains the selected path and I want to get the full path including the file name.

How can I do that?
Posted
Updated 11-Feb-11 2:18am
v4

1 solution

Didn't you post a similar question recently?

I don't think InitialFileName will work as expected all the time. You need to use FileDialog.SelectedItems. In your case since it will be a single filename, you just need to access the first item in that collection.
 
Share this answer
 
Comments
Yasser El Shazly 10-Feb-11 22:32pm    
but this property does not give me the File name With the path

For EX: if i put the file in the path C:\Good\Nice\yaya.xls
the path returned will be Just C:\Good\Nice
and i want to get the full path that is my question
thank
Nish Nishant 10-Feb-11 22:33pm    
Yes I got that. Did you try FileDialog.SelectedItems?
Yasser El Shazly 10-Feb-11 22:37pm    
Fine
You really helped me
thanks
Nish Nishant 10-Feb-11 22:39pm    
So did you get it working now?
Yasser El Shazly 10-Feb-11 22:40pm    
yes i did

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900