Dim oXL As Application
Dim oWB As Workbook
Dim oSheet As Worksheet
Dim oRng As Range
Dim ochart As Microsoft.Office.Interop.Excel.Chart
'Dim objExcel As New Microsoft.Office.Interop.Excel.Application
Try
' Start Excel and get Application object.
oXL = New Microsoft.Office.Interop.Excel.Application
oWB = oXL.Workbooks.Open("c:\\THU\NDP\NDP.xls")
oSheet = oWB.Worksheets(1)
oXL.Visible = True
' Get a new workbook.
oSheet.Cells(5, 1).Value = "Sr #"
oSheet.Cells(5, 2).Value = "Project Name"
With oSheet.Range("A5", "H5")
.Font.Bold = True
.VerticalAlignment = XlVAlign.xlVAlignCenter
.Interior.ColorIndex = 6
End With
oSheet = oWB.Worksheets(3)
' ochart = oSheet.ChartObjects(1)
ochart = oWB.ActiveChart
ochart.HasTitle = True
Catch ex As System.Runtime.InteropServices.COMException
MessageBox.Show("Error accessing Excel: " + ex.ToString())
Catch ex As Exception
MessageBox.Show("Error: " + ex.ToString())
Finally
oRng = Nothing
oXL.DisplayAlerts = False
oSheet = Nothing
oWB.Close()
oWB = Nothing
oXL.Quit()
oXL = Nothing
GC.Collect()
End Try