Change the material of a part via Excel

Hello

 

I'm brand new to SolidWorks (I started making my first parts a week ago :)). Today I want to write in Excel the value of certain variables, make them varied in my solidWorks file. As for the Esquisse I managed to do it. However, to change the materials, I can't do it.

My program for sketching is in two parts, the first which reads the information in my SolidWorks, the second which modifies the solidworks according to the values entered in the Excel.

Here's what I have in my macro:

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2

' Adds the selected dimension to the table
Sub AddSelectedDimension()
    Dim swDimension     As SldWorks.Dimension
    Dim SwMaterial      as SldWorks.MaterialVisualPropertiesData
    Dim exSheet         As Worksheet
    
    Set swApp = CreateObject("SldWorks.Application")
    Set swDoc = swApp.ActiveDoc
    Set exSheet = ThisWorkbook.ActiveSheet

    If swDoc Is Nothing Then
        MsgBox "There is no active document", vbExclamation
        Exit Sub
    End If

    ' Selecting a dimension and assigning it to a cell (row, column)
    Set swDimension = swDoc.Parameter(exSheet.Cells(2, 1))
    exSheet.Cells(2, 2) = swDimension.Value
    Set swDimension = swDoc.Parameter(exSheet.Cells(3, 1))
    exSheet.Cells(3, 2) = swDimension.Value
    Set swDimension = swDoc.Parameter(exSheet.Cells(4, 1))
    exSheet.Cells(4, 2) = swDimension.Value
    Set swDimension = swDoc.Parameter(exSheet.Cells(5, 1))
    exSheet.Cells(5, 2) = swDimension.Value
    Set swDimension = swDoc.Parameter(exSheet.Cells(6, 1))
    exSheet.Cells(6, 2) = swDimension.Value
    Set SwMaterial = swDoc.Parameter(exSheet.Cells(7, 1))
    exSheet.Cells(7, 2) = SwMaterial.Value
    

End Sub

 

 

Attached is a screen of my EXCEL part

   
   
   
   
   
   
   


To display the solidworks values on Excel I click on a Play button and to modify the values I modify them and then I click on an edit values button.

I would like to do the same in the box below (below D1@Plan5) but with the material, is it possible? And if it is, can you help me please ?

 

Anyway, thank you for taking the time to read me:)

 

Kind regards

 

VERMEESCHE Marc

 


captureprogramme.png