SolidWorks drawing to PDF (current sheet only)

calendar_today

2025/12/12

Lightweight macro to save the current drawing sheet as a PDF. It creates a PDF subfolder beside the drawing file and keeps the filename matched to the drawing.

Highlights

  • Checks that a drawing is open and saved.
  • Builds /PDF next to the drawing if missing.
  • Exports only the active sheet via ExportPdfData.
  • Minimal prompts—good for repetitive PDF drops.

Macro (VBA)

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModelDoc As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swDrawingDoc As SldWorks.DrawingDoc
Dim swExportPDFData As SldWorks.ExportPdfData
Dim boolstatus As Boolean
Dim filename As String
Dim lErrors As Long
Dim lWarnings As Long
Dim strSheetName As String

Sub main()
    ' Initializing SolidWorks
    Set swApp = Application.SldWorks

    ' Get document object
    Set swModelDoc = swApp.ActiveDoc
    Set swModelDocExt = swModelDoc.Extension
    Set swExportPDFData = swApp.GetExportFileData(1)

    ' Check if document is a drawing
    If swModelDoc.GetType <> swDocDRAWING Then
        MsgBox "Please open a drawing", vbOKOnly + vbInformation
        Exit Sub
    End If

    ' Query whether document has already been saved
    If swModelDoc.GetPathName = "" Then
        MsgBox "Please save drawing first!", vbOKOnly + vbInformation
        Exit Sub
    End If

    ' Define document as drawing document
    Set swDrawingDoc = swModelDoc

    ' Get the directory path of the drawing document
    Dim docPath As String
    docPath = swModelDoc.GetPathName
    Dim folderPath As String
    folderPath = Left(docPath, InStrRev(docPath, "\"))

    ' Create a new folder named "PDF" if it doesn't exist
    Dim pdfFolderPath As String
    pdfFolderPath = folderPath & "PDF\"
    If Len(Dir(pdfFolderPath, vbDirectory)) = 0 Then
        MkDir pdfFolderPath
    End If

    ' Set file path for PDF = file path of the drawing document + new folder path
    filename = pdfFolderPath & Replace(Mid(docPath, InStrRev(docPath, "\") + 1), ".SLDDRW", ".PDF")

    ' Specify the setting for PDF export that only the current sheet is exported
    boolstatus = swExportPDFData.SetSheets(swExportData_ExportSpecifiedSheets, swDrawingDoc.GetCurrentSheet)

    ' Create a PDF
    boolstatus = swModelDocExt.SaveAs(filename, 0, 0, swExportPDFData, lErrors, lWarnings)

End Sub


Usage

  1. Open the drawing and make sure it is saved.
  2. Activate the sheet you want exported.
  3. Run the macro—PDF lands in /PDF beside the drawing.
  4. Repeat per sheet as needed.