×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

what's the correct syntax to loop through Excel codename uisng NX Journal?

what's the correct syntax to loop through Excel codename uisng NX Journal?

what's the correct syntax to loop through Excel codename uisng NX Journal?

(OP)
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(y)
Next

RE: what's the correct syntax to loop through Excel codename uisng NX Journal?

(OP)
my goal is to loop through each excel sheet to get its codeName instead of the worksheet name, but something wrong with my syntax

i dont want to use the sheet name as reference because user can change sheet name. then, later on, when the progrma runs, the program will throw error saying the sheet doenst exist...

i try to mimic this code written by someone

Function GetWsFromCodeName(wb As Workbook, CodeName As String) As Excel.Worksheet
Dim ws As Excel.Worksheet

For Each ws In wb.Worksheets
If ws.CodeName = CodeName Then
Set GetWsFromCodeName = ws
Exit For
End If
Next ws
End Function

but, i failed after i tried to think about possible correct syntax for NX journal

RE: what's the correct syntax to loop through Excel codename uisng NX Journal?

How about this:

CODE

For i = 1 To objWorkbook.worksheets.count
    MsgBox(objWorkbook.worksheets(i).Codename)
Next 

www.nxjournaling.com

RE: what's the correct syntax to loop through Excel codename uisng NX Journal?

(OP)
Oh my Gee,
Mr, cowski,


you are really my life saver...

changed from
xlsSheetName = objExcel.Worksheets(nXlsSheet).Name
to
xlsCodeName = objExcel.Worksheets(nXlsSheet).codeName


If you dont mind, i have the other question for today:)

I experimentally loop through notes for all table on drawing, my way is to match the title of the table with the codename.
however, i found this is not good, and it will be better to use the Name of the table which can be defined by rightclick > property> general tab> Name...

I look through theUfSession.Tabnot.XXXXXX

none of them give me somethign like getname() which is a property for general notes on drawing...

i know the name of the table notes can be changed, any hint?
you recommened attribute, i am trying something also :)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources