There are a couple issues.
1) You are creating swModel and swModelDoc as ModelDoc2 objects. You are only defining swModelDoc but then you try and use swModel (this causes error 91)
2) The first feature of your feature tree is not a sheetmetal part, it is likely the comments folder. You need to loop through the feature tree to find the type you're looking for before you set an object to that specific variable type.
Try this code:
Option Explicit Dim swApp As SldWorks.SldWorks Dim swFlatPattern As SldWorks.FlatPatternFeatureData Dim swFeat As SldWorks.Feature Dim swModel As SldWorks.ModelDoc2 Dim stringType As String Dim retVal As Boolean Sub main() Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Set swFeat = swModel.FirstFeature Do While Not swFeat Is Nothing stringType = swFeat.GetTypeName2 'Debug.Print stringType If stringType = "FlatPattern" Then Exit Do End If Set swFeat = swFeat.GetNextFeature Loop If Not swFeat Is Nothing Then Set swFlatPattern = swFeat.GetDefinition If swFlatPattern.MergeFace = False Then swFlatPattern.MergeFace = True retVal = swFeat.ModifyDefinition(swFlatPattern, swModel, Nothing) Debug.Print "Merge Faces Changed: " & retVal Else Debug.Print "Merge Faces Change Not Needed" End If End If End Sub
1) I guess I derped and didn't realize I basically had a double initialization.
2) For whatever reason, it was not obvious to me that the tree was being looped through. It seemed like there was some sort of specific command to get access to this specific feature, but the loop method makes a lot of sense given some of the examples I saw where the code had to loop through the tree.
Thank you for the clear explanation. Cheers!