opening an excel workbook in windows service RRS feed

  • Question

  • Dim filePath As String = Application.StartupPath & "\Template.xlsm" If File.Exists(filePath) = False Then Return False End If 'print document Dim oXL As New Excel.Application() Dim oWB As Excel.Workbook Dim oSheet As Excel.Worksheet Try oXL.Visible = False oXL.DisplayAlerts = False oXL.ScreenUpdating = False oWB = oXL.Workbooks.Open(Filename:=filePath, Editable:=False, [ReadOnly]:=True) oSheet = oWB.ActiveSheet

    I am using the same code in windows application. now I am trying to use it in windows service and I am getting an erro "Object reference not set to an instance of an object."

    the system throws an error when the line "oWB = oXL.Workbooks.Open(Filename:=filePath, Editable:=False, [ReadOnly]:=True)" executes. please help.

    Monday, April 28, 2014 6:52 PM


All replies

  • Strange code, are you sure you've used this in a WPF (Windows) application?

     oWB = oXL.Workbooks.Open(Filename:=filePath, Editable:=False, [ReadOnly]:=True)


    Monday, April 28, 2014 7:37 PM
  • i used in winows form application and not wpf.

    can you tell me what is strange please?

    Monday, April 28, 2014 8:01 PM
  • How about this thread:


    Tuesday, April 29, 2014 9:48 AM
  • i used in winows form application and not wpf.

    can you tell me what is strange please?

    A windows application is WPF, maybe you used a Windows Forms application?

    But that is not in the System.Windows Namespace like WPF.


    Tuesday, April 29, 2014 11:17 AM
  • Excel is not designed to be run from a Windows Service application.

    Considerations for server-side Automation of Office

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Tuesday, April 29, 2014 12:03 PM