I am trying to write a VBA macro which I can trigger via approval workflow in PDM to save the BOM in a drawing to an excel spreadsheet.
It seems I'm between a rock in a hard place. I can:
(METHOD A) Pre-select the BOM via mouse click on the "move" icon and loop through the cells, writing each to a spreadsheet,
'traverse the selection and process all selected bill of materials
For i = 1 To Count
If swSelectionManager.GetSelectedObjectType3(i, -1) = swConst.swSelectType_e.swSelANNOTATIONTABLES Then
Set swTableAnnotation = swSelectionManager.GetSelectedObject6(i, -1)
Dim Ret As String
Ret = SaveBOMInExcelWithThumbNail(swTableAnnotation)
If Ret = "" Then
Debug.Print "Success: " & swTableAnnotation.GetAnnotation.GetName
swApp.SendMsgToUser "The selected BOM has been exported with thumbnail preview to Excel."
swApp.SendMsgToUser "Macro failed to export!"
(METHOD B) Loop through the filter tree to automatically to select BOM feature, export to CVS, then save-as XLS.
' Start traversal
While Not swFeature Is Nothing
FeatureName = swFeature.Name
' Do what you want here. I just searched for a BOM called Bill of Materials2
' Change "Bill of Materials2" to the BOM of your choice
If FeatureName = "Bill of Materials2" Then
' Select the sketch in the tree
' Exit early
' Get next feature
Set swFeature = swFeature.GetNextFeature
Exporting to CSV and saving as XLS is very troublesome due to characters in part descriptions. There are commas in virtually all of the part descriptions and I've been unable to find a way to save BOM Feature -> XLS, only BOM Feature -> CSV -> XLS thus eliminating the possibility of selecting a delimiter other than a comma.
Is it possible to combine the "pre-selection click" method A with the "traverse feature tree" method B? Thus avoid the need to pre-select the BOM and also avoiding save-as to CVS -> XLS and the delimiter issue?