Excel.Workbook not defined

To all

I am trying to write a macro to open an excel spreasheet from NX but I ma getting the error
Excel.Workbook not defined

could anyone help/make a suggesting on this one? Code is below

Thanks

JXB

'--------------------------------------
Option Strict Off
Imports System
Imports System.Threading
Imports NXOpen
Imports NXOpenUI
Imports MiniSnap, MiniSnap.Create

Module testxls

Public Sub Main
Dim FileTest As String = "H:\NXMacros\ExcelTestFile.xlsx"
Dim ExcelO As Object
Dim BookO As Excel.Workbook
Dim SheetO As Excel.Worksheet
ExcelO = CreateObject("Excel.Application")
BookO = ExcelO.activeWorkbook
SheetO = ExcelO.Worksheets(1)

Dim testvar1 As String = SheetO.Range("A1").Value
Dim testvar2 As String = SheetO.Range("A2").Value

Dim testvar3 As String = "This is my string to write"
SheetO.Range("A3").Value = testvar3

ExcelO.displayAlerts = False
BookO.SaveAs(FileTest, 51) 'Code 51 is xlsx
BookO.Close()
BookO = Nothing

End Sub
End Module

If you have an author license, you can add a reference to the MSOffice dll's and manage Excel objects directly.

If you do not have an author license, you'll have to do a bit more work. Reference the following threads/posts to get a better idea of how to interact with Excel with a journal.
http://nxjournaling.com/comment/623#comment-623
http://nxjournaling.com/content/export-assembly-excel-pictures

Thanks for the links. Much appreciated

one of the example add a worksheet using
Dim objWorkbook = objExcel.Workbooks.Add

is there a way of opening a (user specified) xls
Dim objWorkbook = objExcel.Workbooks.Open("D:\folder1\myexcelfile.xlsx")

Thanks

Regards

JXB

Thanks
Regards

I think the line of code you listed is the correct syntax.

Dim objExcel = CreateObject("Excel.Application")
Dim objWorkbook = objExcel.Workbooks.Open("D:\folder1\myexcelfile.xlsx")

Workbooks.Open(FileName, UpdateLinks, ReadOnly, Format, Password, WriteResPassword, IgnoreReadOnlyRecommended, Origin, Delimiter, Editable, Notify, Converter, AddToMru, Local, CorruptLoad)

Thanks
Regards

and finally

Dim objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open (FileName:="H:\NXMacros\ExcelTestFile.xlsx", ReadOnly:=False)

Thanks
Regards