Changing Dimension in Part Rather than Assembly

Hello,

I have followed this example:

http://help.solidworks.com/2017/English/api/sldworksapi/Change_Dimension_Example_VB.htm

The example works well for an assembly, but when I try to apply this to a part it will not work.

I changed the file name and also the parameter 'swDocumentTypes_e.swDocASSEMBLY' to 'swDocumentTypes_e.swDocPART'

but I keep getting this error:

Object variable or With block variable not set (Error 91)

at this line:

'Set swDim = swFeature.Parameter("D3")'

I've also changed the dimension names so that they match up with the code.

Can anyone tell me why it is not getting a value?

SolidworksApi macros