Hi!
I'm trying to open a .xls file in vb, but not a specific file. What I need is something like this:

if filename.typefile=.xls then
msgbox ("it's an Excel file")
end if

What I wrote in red colour is the code I need, because I know this code doesn't exist.
Any help?
Thanks in advance.

Hi!
I'm trying to open a .xls file in vb, but not a specific file. What I need is something like this:

if filename.typefile=.xls then
msgbox ("it's an Excel file")
end if

What I wrote in red colour is the code I need, because I know this code doesn't exist.
Any help?
Thanks in advance.

you must get it's extension (.xls) and check it with ".xls" str , or each reserved format.

try this following code, i used InStr() function to search the .xls string in file title of file.

Private Sub btnOpen_Click()
With CommonDialog1
            .Filter = "All Files|*.*|Excel|*.xls"
            .FilterIndex = 4
End With
CommonDialog1.ShowOpen
txtPath.Text = CommonDialog1.FileName
If (InStr(1, CommonDialog1.FileTitle, ".xls", vbBinaryCompare) = 0) Then
    MsgBox "This is not Excel File"
Else
    MsgBox "This is an Excel File"
End If
End Sub

OK. Hope this helps..

Comments
nice post
wow, i never tried this before
This question has already been answered. Start a new discussion instead.