Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extract filename from commondialogbox?

Status
Not open for further replies.
Oct 22, 2001
215
US
I have got the part working for filename info using the common dialogbox. When I retrieve file name from common dialoge box, it comes with the dir too. I just need to get the file name.

Msgbox "You selected" & Commondialogbox1.filename

Any suggestion?
 
Can you give an example of the string you get - I'm sure there's a function to extract the filename using left/mid/right/find etc
Geoff
 
Sure. Write a short function to strip out the filename. It's simple using InStr and Mid$ functions.

Steve King Growth follows a healthy professional curiosity
 
bengalliboy,

Try this:

Msgbox "You selected" & Dir(Commondialogbox1.filename)

Hope this helps.
 
Try the following function....

----------------------------------
Function ExtractFileName(filespec) As String
On Error Resume Next

Dim x As Variant
x = Split(filespec, Application.PathSeparator)
ExtractFileName = x(UBound(x))

On Error GoTo 0

End Function
-----------------------------------
Simon
 
simoncpage,

Is 'Split' a custom function or built-in? I can't seem to find this. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top