Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am trying to open an excel file from vb.net console application.

VB.NET
Imports System
Imports System.Data
Imports Microsoft.Office.Interop

Module Module1
#Region "variables"
    Dim xlapp As Excel.Application
    Dim wbk As Excel.Workbook
    Dim wsht As Excel.Worksheet
    Dim i, j, rowcnt, colcnt As Integer
#End Region

    Sub Main()

        xlapp = CreateObject("Excel.Application")
        wbk = xlapp.Workbooks.Open("D:\TEMPLATE\temp.xlsx")
        wsht = wbk.Worksheets(1)

//data retreival & pasting into excel//
        wbk.SaveAs("D:\REPORT\test.xlsx")

        wsht = Nothing
        wbk = Nothing

        xlapp.Quit()
        xlapp = Nothing

        GC.Collect()

    End Sub

End Module


This line throws the error
wbk = xlapp.Workbooks.Open("D:\TEMPLATE\temp.xlsx")

error is
C#
COMException was unhandled - The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))


Reference for excel included-->
C#
Microsoft.Office.Interop.Excel


I am using Visual Studio 2010 32 bit with framework 3.5 and office 365.
Kindly help as the same code runs fine in another machine that has office 2010 instead of office 365 and rest same.

As I searched on internet, some solutions said to install office on server. Don't know if there is something with office 365.

Thank you....!! :)

What I have tried:

searched for solution but couldn't find any.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900