9 Replies Latest reply on Nov 13, 2015 1:45 PM by Tim Lewis

    Why doesn't VBA let me assign a variable to the class that it ends up being instead of to a generic object?

    Tim Lewis

      The code below works fine when swPart is defined as a generic object, and when I use the TypeName function to get the specific type of object, VBA tells me that it is a "PartDoc".  However, the code below produces the error shown in the screenshot when it is compiled.


      Option Explicit

      Sub Test()

      Dim swApp As SldWorks.SldWorks, swPart As PartDoc


      Set swApp = Application.SldWorks

      Set swPart = swApp.ActivateDoc("Example.sldprt")


      Debug.Print swPart.SetMaterialPropertyName("Custom Materials.sldmat", "Stainless Steel (ferritic)")

      End Sub


      The error:




      Clicking "Okay" puts the editor in debug mode and highlights ".SetMaterialPropertyName".  So my question is, why can't I assign swPart to the class that it ends up being anyhow?