Hi guys, I have an invoke code for exporting chart to image from excel. The code works fine and export chart to image file but keeps on throwing an error Object reference not set to an instance of an object
Try
Dim Application As New Microsoft.Office.Interop.Excel.Application
Dim Workbook As Microsoft.Office.Interop.Excel.Workbook = Application.Workbooks.Open(GID_ReportPath+"\Charts_Combined.xlsx")
Dim WorkSheet As Microsoft.Office.Interop.Excel.Worksheet = CType(Workbook.Sheets("Cashflow_CHART"), Microsoft.Office.Interop.Excel.Worksheet)
Dim ChartObject As Microsoft.Office.Interop.Excel.ChartObject = CType(WorkSheet.ChartObjects("Cashflow_CHART"),Microsoft.Office.Interop.Excel.ChartObject)
Dim Chart As Microsoft.Office.Interop.Excel.Chart = CType(ChartObject.Chart,Microsoft.Office.Interop.Excel.Chart)
Chart.Export(GID_ReportPath+"\Charts_Combined_Cashflow.png","PNG")
Workbook.Close(False)
Workbook = Nothing
Application = Nothing
Application.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(Application)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Please help me if anyone has an idea.