the following code is from nxjournaling.com
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpen.UI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports System.Windows.Forms
Imports System.Collections.Generic
Imports System.Environment
Module replaceTabNotesusingExcelData
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim workPart As Part = theSession.Parts.Work
Dim theUI As UI = UI.GetUI()
Sub Main()
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim objExcel = CreateObject("Excel.Application")
If objExcel Is Nothing Then
MsgBox("Could not start Excel, this journal will now exit.", MsgBoxStyle.Critical, "Error")
Exit Sub
End If
'excel file location
Dim excelFile As String = "e:\excelsheet.xlsx"
If Not IO.File.Exists(excelFile) Then
MsgBox("Specified file not found, journal will now exit.", MsgBoxStyle.Critical, "File not found.")
Exit Sub
End If
'open excel file
Dim objWorkbook = objExcel.Workbooks.Open(excelFile)
If objWorkbook Is Nothing Then
MsgBox("Could not open Excel file, journal will now exit.", MsgBoxStyle.Critical, "Error")
Exit Sub
End If
Dim i As Integer
i = objExcel.activeworkbook.worksheets.count
lw.WriteLine(i)
'my goal is to loop through each excel sheet to get its codename instead of the worksheet name, but something wrong with my syntax
Dim y As String
Dim ws = objWorkbook.objExcel.activeworkbook.worksheets
For Each ws In objExcel.activeworkbook.worksheets
y = objExcel.Worksheet.codeName
MsgBox
Next
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpen.UI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports System.Windows.Forms
Imports System.Collections.Generic
Imports System.Environment
Module replaceTabNotesusingExcelData
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim workPart As Part = theSession.Parts.Work
Dim theUI As UI = UI.GetUI()
Sub Main()
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim objExcel = CreateObject("Excel.Application")
If objExcel Is Nothing Then
MsgBox("Could not start Excel, this journal will now exit.", MsgBoxStyle.Critical, "Error")
Exit Sub
End If
'excel file location
Dim excelFile As String = "e:\excelsheet.xlsx"
If Not IO.File.Exists(excelFile) Then
MsgBox("Specified file not found, journal will now exit.", MsgBoxStyle.Critical, "File not found.")
Exit Sub
End If
'open excel file
Dim objWorkbook = objExcel.Workbooks.Open(excelFile)
If objWorkbook Is Nothing Then
MsgBox("Could not open Excel file, journal will now exit.", MsgBoxStyle.Critical, "Error")
Exit Sub
End If
Dim i As Integer
i = objExcel.activeworkbook.worksheets.count
lw.WriteLine(i)
'my goal is to loop through each excel sheet to get its codename instead of the worksheet name, but something wrong with my syntax
Dim y As String
Dim ws = objWorkbook.objExcel.activeworkbook.worksheets
For Each ws In objExcel.activeworkbook.worksheets
y = objExcel.Worksheet.codeName
MsgBox

Next