Results 1 to 3 of 3

Thread: Open a stored excel file... please help!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    18

    Open a stored excel file... please help!

    I wrote this code to open existing excel sheet,when i run the code, it opens an empty file. Can you please help me?

    Here is the code.

    ________________________________________________________

    Public Sub btmOpen_Click(sender As Object, e As EventArgs)

    Dim ObjExcel As Object
    Dim ObjWS As Object
    Dim Report As Object
    Dim Marshal As Object


    Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\NewUser.xls;Extended Properties= Excel 8.0;HDR=YES;"

    Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)

    ObjExcel = CreateObject("Excel.Application")

    ObjExcel.Visible = True

    'Define o excel workbook
    ObjExcel.Workbooks.Add()
    ObjExcel.Workbooks.Open("NewUser.xls") <<< Here is the problem
    Dim ObjW = ObjExcel.ActiveWorkbook

    ObjWS = ObjExcel.Worksheets("Sheet1")


    ObjWS.Cells(1, 1) = "Excel example"


    ObjW.Save()

    ObjExcel.Quit()
    Marshal.ReleaseComObject(ObjW)
    Marshal.ReleaseComObject(ObjExcel)

    ObjExcel = Nothing
    System.GC.Collect()
    System.GC.Collect()

    End Sub


    ____________________________________________________________


    The error as following:
    Exception Details: System.Runtime.InteropServices.COMException: 'NewUser.xls' could not be found. Check the spelling of the file name, and verify that the file location is correct. If you are trying to open the file from your list of most recently used files on the File menu, make sure that the file has not been renamed, moved, or deleted.


    Orange.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    Re: Open a stored excel file... please help!

    Obvious question: does C:\Inetpub\wwwroot\NewUser.xls exist?

    Check it even if you know it's there.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    18

    Re: Open a stored excel file... please help!

    I checked it before i posted my problem....

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