Create script to add property in assembly and parts SW 2023

I'm trying to create a VBA macro in SolidWorks to automatically add a custom property called "weight" to my documents (parts and/or assemblies). This property should be linked to the SolidWorks mass property (SW-Mass) so that its value updates automatically.

I've been debugging this issue for a while, and despite simplifying the code as much as possible and checking references, I still get the same error on a specific line. I need your help to understand what could be happening.

The idea is that when I run the macro, SolidWorks will:

Find the name of the active document (e.g., MyPart.SLDPRT or MyAssembly.SLDASM).
Create or update a custom property called "weight."


Property Name: weight
Type: Text
Value/Text Expression: 'SW-Mass@MyDocument.SLDxxx' (with single quotes)
Evaluated Value: (e.g.) 5.34 kg

 

SolidWorks 2023 SP5 

VBA 7.1 

SO: Windows 10

Thanks scriptSolidWorks