I am running the same macro on multiple computers, but I am receiving inconsistent results. On certain machines, the macro appears to reset file properties to 0.00000 immediately after saving the STEP file.
Computers are similar: Windows 10 or 11, same SW 2023 SP4, tried sharing SW settings.
An example macro:
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Sub main()
Dim partPath As String
Dim stepPath As String
Dim drawingPath As String
Dim pdfPath As String
Dim errors As Long, warnings As Long
partPath = "C:\\temp\\testpart.SLDPRT"
Set swApp = Application.SldWorks
' Open model file
Set swModel = swApp.OpenDoc6(partPath, swDocPART, swOpenDocOptions_Silent, "", errors, warnings)
If swModel Is Nothing Then
MsgBox "Failed to open: " & partPath
Exit Sub
End If
stepPath = Left(partPath, InStrRev(partPath, ".") - 1) & ".STEP"
swModel.Extension.SaveAs stepPath, 0, 0, Nothing, errors, warnings
' Open model file
' Open drawing file
drawingPath = Left(partPath, InStrRev(partPath, ".")) & "SLDDRW"
If Dir(drawingPath) = "" Then
MsgBox "Drawing not found: " & drawingPath
Exit Sub
End If
Set swDraw = swApp.OpenDoc6(drawingPath, swDocDRAWING, swOpenDocOptions_Silent, "", errors, warnings)
If swDraw Is Nothing Then
MsgBox "Failed to open drawing: " & drawingPath
Exit Sub
End If
pdfPath = Left(drawingPath, InStrRev(drawingPath, ".") - 1) & ".PDF"
swDraw.SaveAs pdfPath
' Open drawing file
' Close the model (optional)
swApp.CloseDoc swModel.GetTitle
MsgBox "Export complete!" & vbCrLf & _
"STEP: " & stepPath & vbCrLf & _
"PDF: " & pdfPath
End Sub
