locked
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

Answers

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)


    Success
    Cor

    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:

    http://stackoverflow.com/questions/5911002/object-reference-not-set-to-an-instance-of-an-object

    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.


    Success
    Cor

    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