Question Can't Open Excel File by using xlApp.Workbooks.Open

villy

Member
Joined
Feb 11, 2009
Messages
10
Programming Experience
Beginner
Hi all,
I would like to open the excel file after create the excel file. The creating file function is done, but the system unable to open the excel file. My coding as below:
----------------------------------------------------------
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook

Dim misValue As Object = System.Reflection.Missing.Value

xlApp = New Excel.ApplicationClass
xlWorkBook = xlApp.Workbooks.Add(misValue)

......

xlWorkBook.SaveAs("C:\testing.xls")

Try
xlWorkBook = xlApp.Workbooks.Open(("C:\testing.xls")
Catch EX As Exception
MsgBox("Open Excel File Error" & EX.Message)
End Try

xlWorkBook.Close()
xlApp.Quit()
releaseObject(xlApp)
releaseObject(xlWorkBook)
--------------------------------------------------------------------

The file can be saved but can't be opened.. any expert know the solution? Thanks!
 
Hi villy


I am facing the same problem tat u have faced.....did u solved....pls share me the updates
 
Use the Interop:

VB.NET:
Public Function OpenExcelWorkbook(Optional ByVal xlsPath As String = Nothing, _
        Optional ByVal isVisible As Boolean = True, _
        Optional ByVal developMssg As Boolean = False) As xlsReturns

        Try
            'initialize
            xlsApp = New Microsoft.Office.Interop.Excel.Application

            'check for path
            If xlsPath <> Nothing Then
                'open indicated workbook
                xlsWrkbk = xlsApp.Workbooks.Open(xlsPath)
            Else
                'open blank workbook
                xlsWrkbk = xlsApp.Workbooks.Add()
            End If

            'turn off alerts
            xlsApp.DisplayAlerts = False

            'check for hidden workbook
            xlsApp.Visible = isVisible

            'set return value
            OpenExcelWorkbook = xlsReturns.Ok
        Catch ex As Exception
            'check for message display
            If developMssg = True Then
                MessageBox.Show(ex.Message)
            End If

            'set return value
            OpenExcelWorkbook = xlsReturns.OpenError
        End Try

    End Function
 
Back
Top