Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Get filename only

Dear all,

How can I just return the filename only (i.e without path) as an
absolute path can be returned by:
fName = Application.GetOpenFilename(FileFilter:="All files (*.*),
*.*", _
Title:="Select a file",
MultiSelect:=False)

Thanks.


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Get filename only

Hi
try the following (will not work in Excel 97 due to InStrRev)
sub foo()
dim fname
fname = application.getopenfilename (FileFilter:="All files (*.*),
*.*", _
Title:="Select a file", MultiSelect:=False)
fname = mid(fname,instrrev(fname,"\")+1,255)
msgbox "You have entered the name:" & fname
end sub

--
Regards
Frank Kabel
Frankfurt, Germany

"kaon " schrieb im Newsbeitrag
...
Dear all,

How can I just return the filename only (i.e without path) as an
absolute path can be returned by:
fName = Application.GetOpenFilename(FileFilter:="All files (*.*),
*.*", _
Title:="Select a file",
MultiSelect:=False)

Thanks.


---
Message posted from http://www.ExcelForum.com/


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Get filename only

Thanks, dude.

I think there is a keyword for that at the beginning

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Get filename only

Hi kaon

For Excel 97 - 2003 you can use this

Sub foo2()
Dim vArr As Variant, fname As Variant
Dim sFileNameXls As String
fname = Application.GetOpenFilename(FileFilter:="All files (*.*),*.*", _
Title:="Select a file", MultiSelect:=False)
vArr = Split97(fname, "\")
sFileNameXls = vArr(UBound(vArr))
MsgBox "You have entered the name:" & sFileNameXls
End Sub

Function Split97(sStr As Variant, sdelim As String) As Variant
'Tom Ogilvy
Split97 = Evaluate("{""" & _
Application.Substitute(sStr, sdelim, """,""") & """}")
End Function


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Frank Kabel" wrote in message ...
Hi
try the following (will not work in Excel 97 due to InStrRev)
sub foo()
dim fname
fname = application.getopenfilename (FileFilter:="All files (*.*),
*.*", _
Title:="Select a file", MultiSelect:=False)
fname = mid(fname,instrrev(fname,"\")+1,255)
msgbox "You have entered the name:" & fname
end sub

--
Regards
Frank Kabel
Frankfurt, Germany

"kaon " schrieb im Newsbeitrag
...
Dear all,

How can I just return the filename only (i.e without path) as an
absolute path can be returned by:
fName = Application.GetOpenFilename(FileFilter:="All files (*.*),
*.*", _
Title:="Select a file",
MultiSelect:=False)

Thanks.


---
Message posted from http://www.ExcelForum.com/




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default Get filename only

kaon

You can also use the Dir function

Dir(fname) will return only the file name

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"kaon " wrote in message
...
Dear all,

How can I just return the filename only (i.e without path) as an
absolute path can be returned by:
fName = Application.GetOpenFilename(FileFilter:="All files (*.*),
*.*", _
Title:="Select a file",
MultiSelect:=False)

Thanks.


---
Message posted from http://www.ExcelForum.com/





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Get filename only

Hi

Why not:

fname = dir(fname)

Regards
Hamilton R. Romano

"Ron de Bruin" wrote in message ...
Hi kaon

For Excel 97 - 2003 you can use this

Sub foo2()
Dim vArr As Variant, fname As Variant
Dim sFileNameXls As String
fname = Application.GetOpenFilename(FileFilter:="All files (*.*),*.*", _
Title:="Select a file", MultiSelect:=False)
vArr = Split97(fname, "\")
sFileNameXls = vArr(UBound(vArr))
MsgBox "You have entered the name:" & sFileNameXls
End Sub

Function Split97(sStr As Variant, sdelim As String) As Variant
'Tom Ogilvy
Split97 = Evaluate("{""" & _
Application.Substitute(sStr, sdelim, """,""") & """}")
End Function


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Frank Kabel" wrote in message ...
Hi
try the following (will not work in Excel 97 due to InStrRev)
sub foo()
dim fname
fname = application.getopenfilename (FileFilter:="All files (*.*),
*.*", _
Title:="Select a file", MultiSelect:=False)
fname = mid(fname,instrrev(fname,"\")+1,255)
msgbox "You have entered the name:" & fname
end sub

--
Regards
Frank Kabel
Frankfurt, Germany

"kaon " schrieb im Newsbeitrag
...
Dear all,

How can I just return the filename only (i.e without path) as an
absolute path can be returned by:
fName = Application.GetOpenFilename(FileFilter:="All files (*.*),
*.*", _
Title:="Select a file",
MultiSelect:=False)

Thanks.


---
Message posted from http://www.ExcelForum.com/


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Get filename only

http://www.cpearson.com/excel/excelF.htm#FileNam

--
Message posted from http://www.ExcelForum.com

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Get filename only

Hi Hamilton

When I want to know this a few years back Tom give me this example and
I always use it since then.

But Dir(fname) Is OK for me<g

Have a nice day



--
Regards Ron de Bruin
http://www.rondebruin.nl


"Hamilton R. Romano" wrote in message om...
Hi

Why not:

fname = dir(fname)

Regards
Hamilton R. Romano

"Ron de Bruin" wrote in message ...
Hi kaon

For Excel 97 - 2003 you can use this

Sub foo2()
Dim vArr As Variant, fname As Variant
Dim sFileNameXls As String
fname = Application.GetOpenFilename(FileFilter:="All files (*.*),*.*", _
Title:="Select a file", MultiSelect:=False)
vArr = Split97(fname, "\")
sFileNameXls = vArr(UBound(vArr))
MsgBox "You have entered the name:" & sFileNameXls
End Sub

Function Split97(sStr As Variant, sdelim As String) As Variant
'Tom Ogilvy
Split97 = Evaluate("{""" & _
Application.Substitute(sStr, sdelim, """,""") & """}")
End Function


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Frank Kabel" wrote in message ...
Hi
try the following (will not work in Excel 97 due to InStrRev)
sub foo()
dim fname
fname = application.getopenfilename (FileFilter:="All files (*.*),
*.*", _
Title:="Select a file", MultiSelect:=False)
fname = mid(fname,instrrev(fname,"\")+1,255)
msgbox "You have entered the name:" & fname
end sub

--
Regards
Frank Kabel
Frankfurt, Germany

"kaon " schrieb im Newsbeitrag
...
Dear all,

How can I just return the filename only (i.e without path) as an
absolute path can be returned by:
fName = Application.GetOpenFilename(FileFilter:="All files (*.*),
*.*", _
Title:="Select a file",
MultiSelect:=False)

Thanks.


---
Message posted from http://www.ExcelForum.com/




  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Get filename only

Hi Dave

Lots of disk access would slow down

Now I can defend myself when I use more code lines<g




--
Regards Ron de Bruin
http://www.rondebruin.nl


"Dave Peterson" wrote in message ...
I suggested the dir(fname), too for a poster who was retrieving lots and lots of
files.

Tom suggested instrrev (or some variation). Lots of disk access would slow down
the procedure more than the instrrev (or some variation).

Made sense to me (well, after I was corrected!).



Ron de Bruin wrote:

Hi Hamilton

When I want to know this a few years back Tom give me this example and
I always use it since then.

But Dir(fname) Is OK for me<g

Have a nice day

--
Regards Ron de Bruin
http://www.rondebruin.nl

"Hamilton R. Romano" wrote in message om...
Hi

Why not:

fname = dir(fname)

Regards
Hamilton R. Romano

"Ron de Bruin" wrote in message ...
Hi kaon

For Excel 97 - 2003 you can use this

Sub foo2()
Dim vArr As Variant, fname As Variant
Dim sFileNameXls As String
fname = Application.GetOpenFilename(FileFilter:="All files (*.*),*.*", _
Title:="Select a file", MultiSelect:=False)
vArr = Split97(fname, "\")
sFileNameXls = vArr(UBound(vArr))
MsgBox "You have entered the name:" & sFileNameXls
End Sub

Function Split97(sStr As Variant, sdelim As String) As Variant
'Tom Ogilvy
Split97 = Evaluate("{""" & _
Application.Substitute(sStr, sdelim, """,""") & """}")
End Function


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Frank Kabel" wrote in message ...
Hi
try the following (will not work in Excel 97 due to InStrRev)
sub foo()
dim fname
fname = application.getopenfilename (FileFilter:="All files (*.*),
*.*", _
Title:="Select a file", MultiSelect:=False)
fname = mid(fname,instrrev(fname,"\")+1,255)
msgbox "You have entered the name:" & fname
end sub

--
Regards
Frank Kabel
Frankfurt, Germany

"kaon " schrieb im Newsbeitrag
...
Dear all,

How can I just return the filename only (i.e without path) as an
absolute path can be returned by:
fName = Application.GetOpenFilename(FileFilter:="All files (*.*),
*.*", _
Title:="Select a file",
MultiSelect:=False)

Thanks.


---
Message posted from http://www.ExcelForum.com/



--

Dave Peterson



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
filename.xls:1 and filename.xls:2 Christina C. Excel Discussion (Misc queries) 7 November 27th 07 10:39 PM
Cell("filename") doesn't update to new filename when do save as. Louis Excel Worksheet Functions 2 March 22nd 07 07:27 PM
set filename to <filename-date on open bob engler Excel Worksheet Functions 2 July 13th 06 05:11 AM
Saving filename same as import filename Matt Excel Programming 4 February 24th 04 03:01 PM
how to specify the filename gptg13 Excel Programming 0 December 18th 03 11:31 PM


All times are GMT +1. The time now is 01:19 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"