|
-
Dec 1st, 2015, 10:44 AM
#1
Thread Starter
Lively Member
[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
Last edited by dday9; Dec 1st, 2015 at 11:24 AM.
-
Dec 1st, 2015, 10:56 AM
#2
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.
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Dec 1st, 2015, 11:24 AM
#3
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.
-
Dec 1st, 2015, 11:50 AM
#4
Re: what is wrong with my code?
 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.
-
Dec 2nd, 2015, 05:36 AM
#5
Thread Starter
Lively Member
Re: what is wrong with my code?
 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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|