GET FILENAME WITHOUT EXTENSION

D

Disperso

hi

i've this macro string for write a filename (that i select) in a cell
without the extension.
In this case the filename remove only the 3 letters of extension. I need a
macro that
remove more long extension (filename.
how i can modify this?

Sub test()
Dim FName As Variant
Dim wb As Workbook
Dim MyPath As String
Dim SaveDriveDir As String
Dim filename As String

SaveDriveDir = CurDir

MyPath = "C:\"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:= _

"Pictures(*.jpg;*.gif;*.bmp), *.jpg;*.gif;*.bmp")

If FName <> False Then
ActiveSheet.Shapes.AddPicture FName, msoTrue, _
msoFalse, 100, 100, 100, 50

filename = Left(Dir(FName), Len(Dir(FName)) - 4)
MsgBox filename

End If

ChDrive SaveDriveDir
ChDir SaveDriveDir

End Sub

(thanks Rob)
 
R

Ron de Bruin

Try this

filename = Left(Dir(FName), Application.WorksheetFunction. _
Find(".", Dir(FName)) - 1)
 
D

Disperso

ok
now how i can paste it on a specific cell ?

Ron de Bruin said:
Try this

filename = Left(Dir(FName), Application.WorksheetFunction. _
Find(".", Dir(FName)) - 1)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top