I downloaded the "Free" version of vb.net from Microsoft. Seems to work fine for "Hello World" programs.
My problem is that no matter what I do I can't access anything in my xlWorkSheet object... The xlWorkBook however
seems to be fine. I know this since I added a second worksheet and my vb.net program was able to see it.
I also tried getting vb.net to 'run' my .VBS script which is able to access and process my worksheet. In the end I can
ctreate a .BAT file to run my .VBS script to cast the .xlsx file to a .csv and have vb.net read it from there?
Why won't this work? Do I need the Professional Version?
Imports System
Imports System.IO
Imports System.Xml
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Excel
Imports Excel = Microsoft.Office.Interop.Excel
Module Program
Sub Main()
Console.WriteLine("Begin MyProgram Excel with VB.Net")
Dim CurrentPath As String
CurrentPath = System.IO.Path.Combine(Directory.GetCurrentDirectory())
Console.WriteLine("Path>" & currentPath)
Dim MyStr As String
Dim xlApp = New Excel.Application
Dim xlWorkBook = xlApp.Workbooks.Open("C:\Users\johnh\Desktop\ExcelFile.xls") ' WORKBOOK TO OPEN THE EXCEL FILE.
Dim xlWorkSheet = xlWorkBook.Worksheets("Sheet1")
MyStr = xlWorkBook.Author
Console.Write("MyStr>" & MyStr & vbCrLf)
MyStr = xlWorkBook.Creator
Console.Write("MyStr>" & MyStr & vbCrLf)
MyStr = xlWorkBook.Sheets.Count
Console.Write("MyStr>" & MyStr & vbCrLf)
'MyStr = xlWorkSheet ??????
'Console.Write("MyStr>" & MyStr & vbCrLf)
xlWorkBook.Close()
xlApp.Quit()
End Sub
End Module
Here is my Console Log:
Begin MyProgram Excel with VB.Net
Path>C:\Users\johnh\Desktop\ExcelRead\ExcelRead\bin\Debug\net6.0
MyStr>John Hoens
MyStr>1480803660
MyStr>2
C:\Users\johnh\Desktop\ExcelRead\ExcelRead\bin\Debug\net6.0\ExcelRead.exe (process 1524) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
My problem is that no matter what I do I can't access anything in my xlWorkSheet object... The xlWorkBook however
seems to be fine. I know this since I added a second worksheet and my vb.net program was able to see it.
I also tried getting vb.net to 'run' my .VBS script which is able to access and process my worksheet. In the end I can
ctreate a .BAT file to run my .VBS script to cast the .xlsx file to a .csv and have vb.net read it from there?
Why won't this work? Do I need the Professional Version?
Imports System
Imports System.IO
Imports System.Xml
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Excel
Imports Excel = Microsoft.Office.Interop.Excel
Module Program
Sub Main()
Console.WriteLine("Begin MyProgram Excel with VB.Net")
Dim CurrentPath As String
CurrentPath = System.IO.Path.Combine(Directory.GetCurrentDirectory())
Console.WriteLine("Path>" & currentPath)
Dim MyStr As String
Dim xlApp = New Excel.Application
Dim xlWorkBook = xlApp.Workbooks.Open("C:\Users\johnh\Desktop\ExcelFile.xls") ' WORKBOOK TO OPEN THE EXCEL FILE.
Dim xlWorkSheet = xlWorkBook.Worksheets("Sheet1")
MyStr = xlWorkBook.Author
Console.Write("MyStr>" & MyStr & vbCrLf)
MyStr = xlWorkBook.Creator
Console.Write("MyStr>" & MyStr & vbCrLf)
MyStr = xlWorkBook.Sheets.Count
Console.Write("MyStr>" & MyStr & vbCrLf)
'MyStr = xlWorkSheet ??????
'Console.Write("MyStr>" & MyStr & vbCrLf)
xlWorkBook.Close()
xlApp.Quit()
End Sub
End Module
Here is my Console Log:
Begin MyProgram Excel with VB.Net
Path>C:\Users\johnh\Desktop\ExcelRead\ExcelRead\bin\Debug\net6.0
MyStr>John Hoens
MyStr>1480803660
MyStr>2
C:\Users\johnh\Desktop\ExcelRead\ExcelRead\bin\Debug\net6.0\ExcelRead.exe (process 1524) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .