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..

commented: wow, i never tried this before +1
commented: nice post +1

Thank you very much. It works!!!

Thank you very much. It works!!!

ok. so mark this thread solved.
all for the best.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.