Results 1 to 5 of 5

Thread: [RESOLVED] what is wrong with my code?

  1. #1

    Thread Starter
    Lively Member elmnas's Avatar
    Join Date
    Jul 2009
    Posts
    127

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

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    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

  3. #3
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,371

    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.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  4. #4
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: what is wrong with my code?

    Quote Originally Posted by dday9 View Post
    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.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  5. #5

    Thread Starter
    Lively Member elmnas's Avatar
    Join Date
    Jul 2009
    Posts
    127

    Re: what is wrong with my code?

    Quote Originally Posted by kebo View Post
    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
  •  



Click Here to Expand Forum to Full Width