Get file extension from listbox cell

Hi All,

I am trying to determine if the cell of a listbox contains a specific extension. Here is what I am trying to use, but no dice:

If Listbox1.ListIndex >= 0 And Listbox1.Cell(Listbox1.LastIndex, 1) = folderItem.Name.Right(6) = “.pages” then
MsgBox “You have found all files that contain the “.pages” extension.”
End If

Any help would be greatly appreciated. Thanks in advance.

You used ListIndex and, later, LastIndex. Is that what you intended?

Even if I stick with ListIndex, I get a type mismatch error for that snippet of code.

folderItem.Name.Right(6 ) = “.pages”

you have a variable called FolderItem ???

I do. I’m sure this is wrong but I can’t figure out the best way to just get the file extension of files from a listbox.

If Listbox1.ListIndex >= 0 And Listbox1.Cell(Listbox1.ListIndex, 1).Right(6) = ".pages" then MsgBox "You have found all files that contain the ".pages" extension." End If

Yeah I would not call it folderitem as thats bound to cause confusion

But is the line AS you wrote it ?

If Listbox1.ListIndex >= 0 And Listbox1.Cell(Listbox1.LastIndex, 1) = folderItem.Name.Right(6 ) = ".pages" then

If so then the second expression is the problem

If Listbox1.ListIndex >= 0 And Listbox1.Cell(Listbox1.LastIndex, 1) = folderItem.Name.Right(6 ) = ".pages" then

this is OK Listbox1.ListIndex >= 0
but Listbox1.Cell(Listbox1.LastIndex, 1) = folderItem.Name.Right(6 ) = ".pages"
isn’t (as for why not I could go into depth IF you want)
Maybe it should be

If Listbox1.ListIndex >= 0 And Listbox1.Cell(Listbox1.ListIndex, 1).Right(6 ) = ".pages" then

Thanks Alex and Norman. This did this trick. One other question for ya. Is there a way to automatically select all files that are dropped onto a listbox?

when you add rows et the rows selected property

something like

listbox.addrow // … whatever it is you do to add your rows
listbox.selected(listbox.lastrow) = true

Ah ha! Thanks again Norman!