[RESOLVED] what is wrong with my code?
hi people,
I have made following code but I can't open the file why?
see code below:
Code:
Imports excel = Microsoft.Office.Interop.Excel
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dlg As New OpenFileDialog
dlg.Filter = " Excel-Arbetsbok(*.xlsx)|*.xlsx|Excel 97-2003-arbetsbok (*.xls)|*.xls)"
dlg.ShowDialog()
Dim FPath As String = IO.Path.GetDirectoryName(dlg.FileName)
Dim XlApp As New Microsoft.Office.Interop.Excel.Application()
Dim wb As Microsoft.Office.Interop.Excel.Workbook = XlApp.Workbooks.Open(FPath & dlg.FileName.ToString())
XlApp.Visible = True
End Sub
No code erros but it says: Couldn't find the file C:\xxx\xxx.test.xlsx is the file moved? renamed or deleted
Re: what is wrong with my code?
Try replacing this
Code:
Dim wb As Microsoft.Office.Interop.Excel.Workbook = XlApp.Workbooks.Open(FPath & dlg.FileName.ToString())
with this...
Code:
Dim wb As Microsoft.Office.Interop.Excel.Workbook = XlApp.Workbooks.Open(dlg.FileName)
The file name includes both the file path and the extension.
Re: what is wrong with my code?
While I appreciate that you included your code, next time could you please wrap it in code tags. To do so, simply hit the # sign in either the quick or advanced reply or you can even type them out manually by typing:
[CODE][/CODE]
I've gone ahead and edited your post to include them.
Re: what is wrong with my code?
Quote:
Originally Posted by
dday9
While I appreciate that you included your code, next time could you please wrap it in code tags. To do so, simply hit the # sign in either the quick or advanced reply or you can even type them out manually by typing:
[CODE][/CODE]
I've gone ahead and edited your post to include them.
Would be nice if there was a button for it to add the [highlight=vb.net][/highlight] or [highlight=vb][/highlight] tags as those make the specific language's code easier to read.
Re: what is wrong with my code?
Quote:
Originally Posted by
kebo
Try replacing this
Code:
Dim wb As Microsoft.Office.Interop.Excel.Workbook = XlApp.Workbooks.Open(FPath & dlg.FileName.ToString())
with this...
Code:
Dim wb As Microsoft.Office.Interop.Excel.Workbook = XlApp.Workbooks.Open(dlg.FileName)
The file name includes both the file path and the extension.
work as a charm! thank you