Error with VBA on SW

Hello All,

I am trying to generate a part using VBA. I copied some code from an online code generator, I pasted it into SW and ran the macro however it is giving me an error. 

' Create a new part document
Set swModel = swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SOLIDWORKS 2023\\templates\\Part.prtdot", 0, 0, 0)
Set swPart = swModel
Set swFeatureMgr = swModel.FeatureManager
Set swSketchMgr = swModel.SketchManager 
 

PLAIN TEXT VERSION:

Set swSketchMgr = swModel.SketchManager


The highlighted line is the one causing the error, can anyone please help me work out where it is going wrong? I am basically a beginner to SW but have done some basic models in the past. 

Thank you.