AnsweredAssumed Answered

Macro to export BOM to Excel works, but won't apply template

Question asked by Dan Sikorski on May 11, 2015
Latest reply on May 11, 2015 by Dan Sikorski

I'm trying to tweak this macro to export an assembly BOM to an excel file in a folder. It works as required, except for the fact it only works when I leave the line


"Const BOMTemplate as String - "" alone


What am I missing? When I add a constant BOMTemplate name (we have a company template) it errors out, and when I put a full directory, it also doesn't work. What does that line of code need to be to grab a specific template each time?





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 = ""
Const OutputPath As String = "H:\PART FILE EXCEL OUTPUT\"

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 & swModel.CustomInfo("Part_Number") & "_0" & ".xls", vbTab
    Set swAnn = swTable.GetAnnotation
    swAnn.Select3 False, Nothing

End Sub