Seperating Extension and File Name

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

I was told I should use this section for my request for help so here I go
again.

I am trying to seperate the extension from a file name so that what I am
left with is an extension and a file name that's stored in String Variables
for re-use later on in the macro. I have no clue how to really do this but
what I have gotten so far is below and apparently that's not all that right
either. Can someone please show me the right way of doing this so I can have
it to refer to in the future, because I can't seem to find it with the help
files of Outlook?

Dim Item As Object
Dim Atmt As Attachment
Dim fExt As String
Dim fName As String

For Each Atmt In Item.Attachments
fExt = Right(Atmt.FileName, 4) 'returns the .??? extension
fName =

For the fName above I tried to do a Trim/RTrim & LTrim but all I get in the
help keeps referring to (Expression) with no clue as to what expression is
the correct expression. Also Apparently there is a possibility of there being
more than three letters and a dot for the extension so now I have to look at
using "InstrRev" to find the dot and then figure out the right side verses
the left side. What if there's more than one dot in the name of the file,
wouldn't that throw it all off??? I have NO idea what to do with that at all.
When I do the F1 deal in the macro editor, well I'm lost at that too.


Thank You Very Much for Your Time and Help.
Rob
 
The InStrRev() function will find the first period, searching from the end of the string:

strAtmtName = Atmt.FileName
intLoc = InStrRev(strAtmtName, ".")
If intLoc > 0 Then
fName = Left(strAtmtName , intLoc - 1)
fExt = Mid(strAtmtName , intLoc + 1)
Else
fName = strAtmtName
fExt = ""
End If

I'd suggest that you read up on the InStrRev, Left and Mid functions in Help, now that you've seen them in action.
 
Hello!

If you will search the web you will find thousands....

fName = left(Atmt.FileName, Len(Atmt.FileName)-4)

CU

Klaus
 
Sweet! Thank You Both! :D


Sue Mosher said:
The InStrRev() function will find the first period, searching from the end of the string:

strAtmtName = Atmt.FileName
intLoc = InStrRev(strAtmtName, ".")
If intLoc > 0 Then
fName = Left(strAtmtName , intLoc - 1)
fExt = Mid(strAtmtName , intLoc + 1)
Else
fName = strAtmtName
fExt = ""
End If

I'd suggest that you read up on the InStrRev, Left and Mid functions in Help, now that you've seen them in action.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
Back
Top