AnsweredAssumed Answered

A macro that copies the values in a specified BOM column and pastes them into cells in different columns

Question asked by 福 谷 勇 時 on Sep 10, 2020
Latest reply on Oct 5, 2020 by Fifi Riri

Please tell me.

I don't know the code, so I would appreciate it if you could tell me.

 

Creates a parts table with the specified template.

I have been able to get the value of the specified column, but I want to paste the value that I got into another column.

I think I can copy and paste with "Ctrl + C" and "Ctrl + V", but I don't understand the code.

It would be perfect if I could copy and paste the values in column 8 into the cells in column 10 after creating the parts list. The variable j specifies the column (8) and the variable i gets the value of RowCount.

I confirmed that there is no problem with the acquired contents in the immediate window display.

Also, I created it by specifying a template, but the thickness of the frame is not reflected for some reason.

Default value? Will be.

I would appreciate if you could tell your code to change the setting to the bounds set in the document properties.

 

Please.

 

Option Explicit

 

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDrawing As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swBOMTableAnnotation As SldWorks.BomTableAnnotation
Dim swTableAnnotation As SldWorks.TableAnnotation

 

Dim nNumRow As Long
Dim sRowStr As String

 

Dim i As Long
Dim j As Long

 

Dim anchorType As Long
Dim bomType As Long
Dim tableTemplate As String
Dim config As String

 


Sub main()

 

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    
    If swModel Is Nothing Then
    MsgBox "The file is not open" & vbCrLf & "Open the file and execute the macro", vbCritical
    GoTo Err1
    End If
        
    Dim Doctype As Long
    Doctype = swModel.GetType
    
    If Doctype <> 3 Then
    MsgBox "No drawing selected" & vbCrLf & "Select the drawing and execute the macro", vbCritical
    GoTo Err1
    End If
    
'BOM creation Vew designation

 

    Set swDrawing = swModel
    Set swView = swDrawing.GetCurrentSheet.GetViews()(0)

 

'BOM creation

 

    anchorType = swBOMConfigurationAnchor_TopRight
    bomType = swBomType_TopLevelOnly
    
    tableTemplate = "My template.sldbomtbt"
        
    config = ""
    
    On Error Resume Next
    
    Set swBOMTableAnnotation = swView.InsertBomTable4(True, 0, 0, anchorType, bomType, config, tableTemplate, False, swNumberingType_Detailed, False)
    Set swTableAnnotation = swBOMTableAnnotation
    
    If Err.Number > 0 Then
        MsgBox "Could not create BOM" & vbCrLf & "Please start over", vbInformation
        On Error GoTo 0
    GoTo Err1
    End If
    On Error GoTo 0
        
'Get the number of BOM rows

 

    nNumRow = swTableAnnotation.RowCount

 


'Get the value of the specified column

 

       j = 8
       
    For i = 1 To nNumRow - 1
        sRowStr = ""

 

            sRowStr = sRowStr & swTableAnnotation.Text2(i, j, True) & ","

 

        Debug.Print Left(sRowStr, Len(sRowStr) - 1)
        
   'Here, I want to copy the contents of variable i from column 10 row 1 to NEXT.
        
    Next i

 

Err1:

 

    Set swApp = Nothing
    Set swModel = Nothing
    Set swDrawing = Nothing

 

End Sub

Outcomes