Sub Main() 'This sub will export the categories and names of all materials and their appearance and physical assets 'in the active material library To an excel file. '[ Variables Dim j As Integer ' Speadsheet data row counter j = 6 ' Start data entry on row j, '( row 1 is Title, 2 is Library Name, 3 is library internal name, 4 is library location, (path), 5 is headers) '] '[ 'Set reference to Inventor application Dim InvApp As Inventor.Application Dim AML As AssetLibrary Dim cat As AssetCategory Dim ma As MaterialAsset 'Get the Inventor Application object. InvApp = ThisApplication 'Get the Active Material Library AML = InvApp.ActiveMaterialLibrary '] '[ Set Excel file path and name myPath = ThisDoc.Path myFileName = iProperties.Value("project", "Part Number") & ".xlsx" path_and_name = myPath & "\" & myFileName '] '[ Open Excel excelApp = CreateObject("Excel.Application") excelApp.Visible = True excelApp.DisplayAlerts = True '] '[ Check for existing excel file Or create one if not existing. If Dir(path_and_name) <> "" Then 'workbook exists, open it excelWorkbook = excelApp.Workbooks.Open(path_and_name) 'set the first sheet active excelSheet = excelWorkbook.Worksheets(1).activate With excelApp 'Clear existing data .Range("A1:E1000").delete End With Else 'workbook does Not exist, create it excelWorkbook = excelApp.Workbooks.Add excelSheet = excelWorkbook.Worksheets(1).activate excelWorkbook.SaveAs(path_and_name) End If excelWorkbook.Save() '] '[ Excel Column Headers With excelApp .Range("a5").value = "Category Name" .Range("b5").Value = "Material Name" .Range("c5").Value = "Appearance Asset" .Range("d5").Value = "Physical Asset" End With '] '[ 'write spreadsheet title, library display name, internal name, and file path to excel With excelApp .Range("a1").value = "INVENTOR MATERIALS LIST" .Range("A2").value = "Library Display Name: " .Range("b2").value = AML.DisplayName .Range("a3").value = "Library Internal Name: " .Range("b3").value = AML.InternalName .Range("A4").value = "Library Location: " .Range("b4").value = AML.FullFileName End With '] '[ 'Write material library list to excel With excelApp 'Iterate through material categories For Each cat In AML.MaterialAssetCategories .Range("a" & j).value = cat.DisplayName j= j + 1 'Iterate through each material in the category For Each ma In cat.Assets .Range("b" & j).value = ma.DisplayName .Range("c" & j).value = ma.AppearanceAsset.DisplayName .Range("d" & j).value = ma.PhysicalPropertiesAsset.DisplayName j = j + 1 Next j = j + 1 Next End With '] '[ Save and Close Excel excelWorkbook.Save() ' excelWorkbook.Close ' excelApp.Quit ' excelApp = Nothing ' MessageBox.Show("Exported Data to Excel", "Data Exported to Excel") '] End Sub