0

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.

3
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by Jx_Man
Featured Replies
  • 2

    try this following code, i used InStr() function to search the .xls string in file title of file. [CODE]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" … Read More

0

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.

2

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.
Be sure to adhere to our posting rules.