Macro works fine for me. However I got it to throw the same error, by having "configuration" set wrong. I ran it on a assembly that didn't have a "default" and it threw the error. Worked fine on a assembly that has a "default" configuration.
Also if the Template name or file location is wrong...same error.
You need to add some checks on the variables to make sure they satisfy the macro...ie, Assembly must contain a "default" configuration or prompt & end macro...
Thanks for your response, I can now understand why this doesn't work now. The configuration name in all my assembly files are not set as 'Default'. They all have custom specific names.
I changed the 'Configurations line' so that it would grab the active configuration name, but its giving me another error. Any ideas why?
New code below:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.AssemblyDoc
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swBOMAnnotation As SldWorks.BomTableAnnotation
Dim swBOMFeature As SldWorks.BomFeature
Dim swNote As SldWorks.Note
Dim boolstatus As Boolean
Dim BomType As Long
Dim Configuration As String
Dim TemplateName As String
Dim nErrors As Long
Dim nWarnings As Long
Dim swConfig As SldWorks.Configuration
Set swApp = Application.SldWorks
' Open assembly document
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
' Insert BOM table
TemplateName = "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\lang\english\bom-kelvin_test_template.sldbomtbt"
BomType = swBomType_PartsOnly
Set swConfig = swModel.GetActiveConfiguration 'New code not working*
Configuration = swConfig.Name 'New code not working*
Set swBOMAnnotation = swModelDocExt.InsertBomTable3(TemplateName, 0, 1, BomType, Configuration, False, swNumberingType_Detailed, True)
Set swBOMFeature = swBOMAnnotation.BomFeature
Runs fine for me.
Yeah its working for me now after I restarted Solidworks. Strange. Many thanks for your help.