I always get an error with Line 39. It always have NullPointerException error. Could you check what is the error? Here's my code
Imports System.Runtime.InteropServices
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim filen As String
filen = TextBox1.Text
test(filen)
End Sub
Sub test(byval filen)
Dim oApp As Microsoft.Office.Interop.Excel.Application
oApp = New Microsoft.Office.Interop.Excel.Application
Dim oldCI As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
oApp.Workbooks.Add()
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI
Dim excel As Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
Dim wc As Microsoft.Office.Interop.Excel.Chart
Try
excel = New Microsoft.Office.Interop.Excel.Application
wb = excel.Workbooks.Open(filen)
excel.Visible = True
wb.Activate()
ws = New Microsoft.Office.Interop.Excel.Worksheet
ws = wb.Worksheets("Sheet1")
wc = New Microsoft.Office.Interop.Excel.Chart
wc = ws.ChartObjects(1).Activate
wc.ActiveChart.Export(Filename:="C:\Users\mark.perfinan\Documents\trusted\" + wc.ActiveChart.Name + ".png", FilterName:="PNG")
Catch ex As COMException
MessageBox.Show("Error accessing Excel: " + ex.ToString())
Catch ex As Exception
MessageBox.Show("Error: " + ex.ToString())
End Try
'wb.Worksheets().ChartObjects().Chart.Export(filename:="C:\Users\mark.perfinan\Documents\trusted\" + wb.Worksheets(ActiveSheet.Index).ChartObjects().Chart.Name + ".png", filtername:="PNG")
'ActiveChart.Export(filename:="C:\Users\xxxxxxxx\Documents\trusted\" + ActiveChart.Name + ".png", filterName:="png")
End Sub
End Class