Hi,
I want to export a BOM with VBA or iLogic Rules to Excel (and after, we use VBA for doing some operation in the Excel). If I use small BOM (I tested with 150 rows), it's working fine. But I tried with a larger one (750 rows) and it's generate the Excel file but it's seem corrupted (I can open it, but can't do any modification because Excel open it in safe mode and I can't desactivate it).
If I use the standard way to export BOM to Excel, it's working fine. I have put 3 excel files :
Large BOM Standard Way Working.xlsx - Generated with the inventor way to export BOM
Small BOM Working.xls - Generated using VBA Code
Large BOM NOT WORKING.xls - Generated using VBA Code
Anyway having a similar problem ?
This is the iLogic Rules Code (Just used for testing)
oDoc = ThisDoc.ModelDocument
'Ensure that we are in an Assembly file - Exit if not
If oDoc.DocumentType = kPartDocumentObject Then
MessageBox.Show("Le fichier doit être un assemblage pour exporter le BOM.", "Pro-Métal Plus")
Return
End If
oDoc = ThisApplication.ActiveDocument
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
'**************************************************************************************
'You can change the output path by editing CSVpath below - by default the path is the same as the assembly file
'CSVpath = ("C:\Inventor\") 'If you change the path, remember to keep a \ at the end
CSVpath = ThisDoc.Path + "\"
'**************************************************************************************
' the structured view to 'all levels'
oBOM.StructuredViewFirstLevelOnly = False
' Make sure that the structured view is enabled.
oBOM.StructuredViewEnabled = True
Dim oStructuredBOMView As BOMView
oStructuredBOMView = oBOM.BOMViews.Item("Structuré")
' Export the BOM view to an Excel file
oStructuredBOMView.Export(CSVpath + ThisDoc.FileName(False) + ".xls", kMicrosoftExcelFormat)
And this is the code I used in VBA :
' Set a reference to the assembly document.
' This assumes an assembly document is active.
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
' Set a reference to the BOM
Dim oBOM As BOM
Set oBOM = oDoc.ComponentDefinition.BOM
' Set the structured view to 'all levels'
oBOM.StructuredViewFirstLevelOnly = False
' Make sure that the structured view is enabled.
oBOM.StructuredViewEnabled = True
' Set a reference to the "Structured" BOMView
Dim oStructuredBOMView As BOMView
Set oStructuredBOMView = oBOM.BOMViews.Item("Structuré")
Dim file_name2 As String
Dim MyValue As Integer
MyValue = Int((659 * Rnd) + 1)
Dim oPartNumProperty As String
oPartNumProperty = oDoc.ComponentDefinition.Document.PropertySets( _
"Design Tracking Properties")("Part Number").Value
file_name2 = "C:\temp\BOM-" & oPartNumProperty & ".xls"
FormAtt.Show
DoEvents
oStructuredBOMView.Export file_name2, kMicrosoftExcelFormat
FormAtt.Hide
'Ouvrir le fichier Excel et récupérer le document
Dim excelApp As Excel.Application
Dim file_name As String
'Try to connect to a running instance of Excel.
On Error Resume Next
Set excelApp = GetObject(, "Excel.Application")
If Err Then
Err.Clear
'Couldn't connect so start Excel. It's started invisibly.
Set excelApp = CreateObject("Excel.Application")
If Err Then
MsgBox "Erreur : Impossible d'accéder au document Excel (1). Erreur " & Err
Exit Sub
End If
End If
'Ouvrir le Excel avec le BOM
Dim wb As Workbook
Set wb = excelApp.Workbooks.Open(file_name2)
If Err Then
MsgBox "Erreur : Impossible d'accéder au document Excel (2). " & file_name2
Exit Sub
End If
Office 365 not supported!
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
"Office 365 subscribers must ensure they have a local installation of Microsoft Excel." ; Installation of Office 365 is local. May be I should have specified that I use the version 2016 provided by the 365 subscription...
"Inventor workflows that read or export spreadsheet data do not require Microsoft® Excel." So export should work even if I don't have a local install (but I have one).
And like I wrote, small BOM export work, so the problem is not the installation of Excel or the unsupported brower base Office 365 that I don't use.
@Anonymous , you could try changing the file extension in your export code. Change ".xls" to ".xlsx". That's the newer Excel format.
Can't find what you're looking for? Ask the community or share your knowledge.