Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

hi @A.Acheson 

Thank you for your reply.

I have continuously learned through communit and help. And I am trying to solve some codes by changing them. However, I succeeded in getting "Existing Item Name" and "Change Item Name" from Excel, but I failed to change it by applying it in order. The following is the code that I changed through learning. Please give me various opinions.

 

 

Imports System.Windows.Forms

' Excel 파일 열기 및 데이터 처리
Sub Main()
    ' Excel 파일 열기
    GoExcel.Open("TEST.xlsx", "Sheet1")

    ' 기존품명과 변경품명을 저장할 List 선언
    Dim i As Integer = 2
    Dim oldNameList, newNameList As New List(Of String)

    ' 기존품명 열의 Excel 열 이름 가져오기
    oldCol = GetExcelColumnName(GoExcel.FindColumn("기존품명"))
    ' 변경품명 열의 Excel 열 이름 가져오기
    newCol = Chr(Asc(oldCol) + 1)

    ' Excel에서 데이터 읽어오기
    While GoExcel.CellValue("TEST.xlsx", "Sheet1", oldCol & i) > ""
        ' 기존품명과 변경품명 데이터를 List에 추가
        oldNameList.Add(GoExcel.CellValue("TEST.xlsx", "Sheet1", oldCol & i))
        newNameList.Add(GoExcel.CellValue("TEST.xlsx", "Sheet1", newCol & i))
        i += 1
    End While

    ' 사용자에게 폴더 선택 받기
    Dim ExportPath As String = ""

    Using Dialog As New FolderBrowserDialog()
        Dialog.SelectedPath = "C:\" ' 기본 경로 설정
        Dialog.ShowNewFolderButton = True
        Dialog.Description = "Choose Folder for Export..."

        ' 폴더 선택 대화상자 표시
        If DialogResult.OK = Dialog.ShowDialog() Then
            ExportPath = Dialog.SelectedPath & "\"
        Else
            Return ' 취소되었을 때 처리
        End If
    End Using

    ' Inventor 문서 및 참조 문서 가져오기
    Dim InvDoc As Document = ThisDoc.Document
    Dim refDocs As DocumentsEnumerator = InvDoc.AllReferencedDocuments

    ' 각 부품의 이름을 변경하여 저장
    For Each refDoc As Document In refDocs
        For j As Integer = 0 To oldNameList.Count - 1
            ' 부품 이름 확인 및 변경 후 저장
            If refDoc.DisplayName.EndsWith(oldNameList(j) & ".ipt") Then
                refDoc.SaveAs(ExportPath & newNameList(j) & ".ipt", False)
            End If
        Next
    Next

    ' Excel 파일 닫기
    GoExcel.Close()

    ' 처리된 파일 수를 메시지 박스로 표시
    MessageBox.Show(oldNameList.Count.ToString + " file(s) Complete!")
End Sub

' 열 번호를 Excel 열 이름으로 변환하는 함수
Function GetExcelColumnName(columnNumber As Integer) As String
    Dim dividend As Integer = columnNumber
    Dim columnName As String = String.Empty
    Dim modulo As Integer

    While dividend > 0
        modulo = (dividend - 1) Mod 26
        columnName = Convert.ToChar(65 + modulo).ToString() & columnName
        dividend = CInt((dividend - modulo) / 26)
    End While

    Return columnName
End Function

 

 

jthzzang1KQJ5G_0-1704247227700.png