Problem with Macro in Solidworks 2024

Hi all,

I have problem with using Macro in Solidworks 2024. Whatever code that I write, I see the following error and even when I record a simple Macro and want to run it, I see the following error:

"Runtime error 91 Object variable or with block variable not set"

and in debug section, this line is highlighted:

StudyManagerObj = Nothing
 

It seems like there's something wrong with macro feature in my software. Here's the entire Macro:

' ******************************************************************************
' C:\Users\AAA\AppData\Local\Temp\swx20316\Macro1.swb - macro recorded on 03/25/25 by AAA
' ******************************************************************************
Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
Dim COSMOSWORKSObj As Object
Dim CWAddinCallBackObj As Object
Set CWAddinCallBackObj = swApp.GetAddInObject("CosmosWorks.CosmosWorks")
Set COSMOSWORKSObj = CWAddinCallBackObj.COSMOSWORKS
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized

' Save As
longstatus = Part.SaveAs3("E:\AAA\Part1.SLDPRT", 0, 0)
StudyManagerObj = Nothing
ActiveDocObj = Nothing
Set CWAddinCallBackObj = Nothing
Set COSMOSWORKSObj = Nothing
End Sub