AnsweredAssumed Answered

How to Export BOM directly to a Excel File XLS or XLSX Not CVS

Question asked by Cad Admin on Oct 13, 2016
Latest reply on Oct 13, 2016 by Deepak Gupta

I have used the below Macro for years.  Now all of a sudden is is an issue, with the cvs/xls import issues.  Basically the macro creates a CVS file through SaveAsText, but the macro gives it an .xls file extension.  When the file is opened, the user is prompted to "fix" it.  Now all of a sudden I'm getting flack for this.

 

Can SaveAsExcelFile be used here instead? or is there any other way(s)?

 

 

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swBOMTable As SldWorks.BomTableAnnotation

Dim swTable As SldWorks.TableAnnotation

Dim swAnn As SldWorks.Annotation

Const BOMTemplate As String = "D:\Custom Paths\BOM Template\BOM-STD.sldbomtbt"

Const OutputPath As String = "D:\Test Data\"

 

Dim ConfigName As String

Sub main()

    Set swApp = Application.SldWorks

 

    Set swModel = swApp.ActiveDoc

            ConfigName = swModel.GetActiveConfiguration.Name

    Set swBOMTable = swModel.Extension.InsertBomTable(BOMTemplate, 0, 0, swBomType_e.swBomType_Indented, ConfigName)

 

            Set swTable = swBOMTable

 

    swTable.SaveAsText OutputPath & "BOM " & swModel.CustomInfo("SW-File Name") & "_0" & ".xls", vbTab

    Set swAnn = swTable.GetAnnotation

    swAnn.Select3 False, Nothing

 

    swModel.EditDelete

End Sub

Outcomes