[MACRO] Need Assistance Saving .STL to Desktop

Hello, I am having trouble figuring out how to create a macro that saves the current SOLIDWORKS Part file as an .STL file ONTO the Desktop. This was not my code. I found it online and tried to reverse engineer it to save it to desktop instead of the part file's folder, but am calling it quits and am seeking help. 

Dim swApp As SldWorks.SldWorks

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

Sub main()

   Set swApp = _
   Application.SldWorks

   Set Part = swApp.ActiveDoc
   If Part Is Nothing Then Exit Sub

   Dim Path As String
   Path = Part.GetPathName
   If Part.GetType = swDocDRAWING Then
      Exit Sub
End If

   Dim Extension As String
   Extension = Mid(Path, InStrRev(Path, "."))
   Path = Replace(Path, Extension, ".stl")
   Extension = ".stl"

   longstatus = Part.SaveAs3(Path, 0, 0)

   MsgBox "Saved " & Path, vbInformation
End Sub

Anything would be appreciated, thank you.

SolidworksApi/macros
Answers 1
FR
FR 2021-04-09 Best Answer

Hello. Try this:

Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim boolstatus As Boolean
Dim FileName As String
Dim Path As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then Exit Sub
Path = swModel.GetPathName
If swModel.GetType = swDocDRAWING Then Exit Sub
FileName = Mid(Path, InStrRev(Path, "\"), InStrRev(Path, ".") - InStrRev(Path, "\"))
Path = CreateObject("WScript.Shell").specialfolders("Desktop") & FileName & ".stl"
boolstatus = swModel.Extension.SaveAs(Path, swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, Empty, Empty)
MsgBox "Saved " & Path, vbInformation
End Sub