View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
What-A-Tool What-A-Tool is offline
external usenet poster
 
Posts: 14
Default How to extract file extensions?


"DK" wrote in message
ps.com...
I have a directory listing for all the files in a particular drive.
With excel macros, I have extracted filenames with extension in column
E. like filename.xxx

i need to extract the extensions in Column F. Now, column E does not
have all files with extensions.

Extension should be extracted with a condition of having a dot and 3
letter extension.

Can someone please help me in writing a small code?


Put this together for use in an Access database I worked on a while back -
not claiming its the best way - some of the more knowledgeable people around
here may be able to point out a better method - but its always worked for
me.
Good luck - Sean

Private Function GetExtension(ByVal strPath As String) As String
'Get file extension from file name
Dim intPtLoc As Integer
intPtLoc = InStrRev(strPath, ".")
GetExtension = UCase(Right(strPath, (Len(strPath) - (intPtLoc))))
End Function