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

Hi All
In a file open dialog I get the full file path and filename and extension.
eg

C:\mydocumentspath\subpath\myfile.xls

What is the best method to extract the filename extension only eg

myfile.xls

--
Cheers
Nigel




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Extracting filename

Use the instrRev function to get the last \

sFile = "C:\mydocumentspath\subpath\myfile.xls"

iPos = InStrRev(sFile, "\")
If iPos 0 Then
Debug.Print Right(sFile, Len(sFile) - iPos)
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Nigel" wrote in message
...
Hi All
In a file open dialog I get the full file path and filename and extension.
eg



What is the best method to extract the filename extension only eg

myfile.xls

--
Cheers
Nigel






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Extracting filename

To get myfile.xls use:-
FileNm = activeWorkbook.Name

If it's the file extention you want (ie xls):-
Extn = Right(ActiveWorkbook.Name, 3)

Hope those work as haven't tryed them!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Extracting filename

in VB I use this:

Public FileSys As New FileSystemObject
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Extracting filename

Thanks Chaps

--
Cheers
Nigel



wrote in message
oups.com...
To get myfile.xls use:-
FileNm = activeWorkbook.Name

If it's the file extention you want (ie xls):-
Extn = Right(ActiveWorkbook.Name, 3)

Hope those work as haven't tryed them!





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Extracting filename

Hi Bob,
I was toying with instr but did not know about the reverse version. Do you
know if this exists in xl97 - I am developing in xl2002 but the final
product will run in xl97 and at present I cannot test it?

--
Cheers
Nigel



"Bob Phillips" wrote in message
...
Use the instrRev function to get the last \

sFile = "C:\mydocumentspath\subpath\myfile.xls"

iPos = InStrRev(sFile, "\")
If iPos 0 Then
Debug.Print Right(sFile, Len(sFile) - iPos)
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Nigel" wrote in message
...
Hi All
In a file open dialog I get the full file path and filename and

extension.
eg



What is the best method to extract the filename extension only eg

myfile.xls

--
Cheers
Nigel








  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Extracting filename

No, it is not available in xl97, but easy to code it yourself.

--
Regards,
Tom Ogilvy

"Nigel" wrote in message
...
Hi Bob,
I was toying with instr but did not know about the reverse version. Do

you
know if this exists in xl97 - I am developing in xl2002 but the final
product will run in xl97 and at present I cannot test it?

--
Cheers
Nigel



"Bob Phillips" wrote in message
...
Use the instrRev function to get the last \

sFile = "C:\mydocumentspath\subpath\myfile.xls"

iPos = InStrRev(sFile, "\")
If iPos 0 Then
Debug.Print Right(sFile, Len(sFile) - iPos)
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Nigel" wrote in message
...
Hi All
In a file open dialog I get the full file path and filename and

extension.
eg



What is the best method to extract the filename extension only eg

myfile.xls

--
Cheers
Nigel










  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Extracting filename

Thanks Tom, so I will need to emaulate this in xl97. What is the best
approach?

--
Cheers
Nigel



"Tom Ogilvy" wrote in message
...
No, it is not available in xl97, but easy to code it yourself.

--
Regards,
Tom Ogilvy

"Nigel" wrote in message
...
Hi Bob,
I was toying with instr but did not know about the reverse version. Do

you
know if this exists in xl97 - I am developing in xl2002 but the final
product will run in xl97 and at present I cannot test it?

--
Cheers
Nigel



"Bob Phillips" wrote in message
...
Use the instrRev function to get the last \

sFile = "C:\mydocumentspath\subpath\myfile.xls"

iPos = InStrRev(sFile, "\")
If iPos 0 Then
Debug.Print Right(sFile, Len(sFile) - iPos)
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Nigel" wrote in message
...
Hi All
In a file open dialog I get the full file path and filename and

extension.
eg



What is the best method to extract the filename extension only eg

myfile.xls

--
Cheers
Nigel












  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Extracting filename

Nigel,

Nigel wrote:
Hi Bob,
I was toying with instr but did not know about the reverse version.
Do you know if this exists in xl97 - I am developing in xl2002 but
the final product will run in xl97 and at present I cannot test it?


No, InStrRev was introduced in Excel 2000.

Here's an example using the FileSytemObject:

Public Function gsGetFileName(rsPath As String) As String
Dim fso As Object

On Error GoTo ErrHandler

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(rsPath) Then gsGetFileName = _
fso.GetFileName(rsPath)

ExitRoutine:
Set fso = Nothing
Exit Function
ErrHandler:
MsgBox Err.Number & ": " & Err.Description
Resume ExitRoutine
End Function


--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Extracting filename

Just write a loop from the right backwards

For iPos = Len(sFile) to 1
If mid(sFil;e,iPos,1) = "\" Then
Exit For
End If
Next iPos

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Nigel" wrote in message
...
Thanks Tom, so I will need to emaulate this in xl97. What is the best
approach?

--
Cheers
Nigel



"Tom Ogilvy" wrote in message
...
No, it is not available in xl97, but easy to code it yourself.

--
Regards,
Tom Ogilvy

"Nigel" wrote in message
...
Hi Bob,
I was toying with instr but did not know about the reverse version.

Do
you
know if this exists in xl97 - I am developing in xl2002 but the final
product will run in xl97 and at present I cannot test it?

--
Cheers
Nigel



"Bob Phillips" wrote in message
...
Use the instrRev function to get the last \

sFile = "C:\mydocumentspath\subpath\myfile.xls"

iPos = InStrRev(sFile, "\")
If iPos 0 Then
Debug.Print Right(sFile, Len(sFile) - iPos)
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Nigel" wrote in message
...
Hi All
In a file open dialog I get the full file path and filename and
extension.
eg



What is the best method to extract the filename extension only eg

myfile.xls

--
Cheers
Nigel
















  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Extracting filename

Hi Bob,
Of course - I'm just not thinking - it's been a long day, dealing with Class
Modules! (reference other posts)

--
Cheers
Nigel



"Bob Phillips" wrote in message
...
Just write a loop from the right backwards

For iPos = Len(sFile) to 1
If mid(sFil;e,iPos,1) = "\" Then
Exit For
End If
Next iPos

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Nigel" wrote in message
...
Thanks Tom, so I will need to emaulate this in xl97. What is the best
approach?

--
Cheers
Nigel



"Tom Ogilvy" wrote in message
...
No, it is not available in xl97, but easy to code it yourself.

--
Regards,
Tom Ogilvy

"Nigel" wrote in message
...
Hi Bob,
I was toying with instr but did not know about the reverse version.

Do
you
know if this exists in xl97 - I am developing in xl2002 but the

final
product will run in xl97 and at present I cannot test it?

--
Cheers
Nigel



"Bob Phillips" wrote in message
...
Use the instrRev function to get the last \

sFile = "C:\mydocumentspath\subpath\myfile.xls"

iPos = InStrRev(sFile, "\")
If iPos 0 Then
Debug.Print Right(sFile, Len(sFile) - iPos)
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Nigel" wrote in message
...
Hi All
In a file open dialog I get the full file path and filename and
extension.
eg



What is the best method to extract the filename extension only

eg

myfile.xls

--
Cheers
Nigel
















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
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
& Filename teresa Excel Programming 1 December 27th 04 02:05 PM
Saving filename same as import filename Matt Excel Programming 4 February 24th 04 03:01 PM
extracting a stringvalue from filename solo_razor[_24_] Excel Programming 1 November 4th 03 10:26 AM


All times are GMT +1. The time now is 01:09 AM.

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

About Us

"It's about Microsoft Excel"