Hide Table of Contents

Save File as PDF Example (VBA)

This example shows how to export the specified sheet in a drawing document to a PDF file.

'----------------------------------------------------------------------------
' Preconditions:
' 1. Verify that the specified drawing document to open exists.
' 2. Verify that the folder (c:\test) to which to save
'    the PDF file exists. If it does not exist,
'    create it or change the path to a folder that
'    exists on your system.
'
' Postconditions:
' 1. Opens the specified drawing document.
' 2. Saves all but the last drawing sheet to an array.
' 3. Saves the array of drawing sheets to a PDF file
'    called foodprocessor.pdf.
' 4. Opens foodprocessor.pdf.
'----------------------------------------------------------------------------

Option Explicit

    Dim swApp               As SldWorks.SldWorks
    Dim swModel             As SldWorks.ModelDoc2
    Dim swModelDocExt       As SldWorks.ModelDocExtension
    Dim swExportPDFData     As SldWorks.ExportPdfData
    Dim boolstatus          As Boolean
    Dim filename            As String
    Dim lErrors             As Long
    Dim lWarnings           As Long
    Dim strSheetName(4)     As String
    Dim varSheetName        As Variant

Sub main()

    ' Path to which to save PDF file of drawing
    filename = "C:\foodprocessor.PDF"

    Set swApp = Application.SldWorks
    swApp.Visible = True

    ' Open specified drawing
    Set swModel = swApp.OpenDoc6("c:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\samples\tutorial\advdrawings\foodprocessor.slddrw", swDocDRAWING, swOpenDocOptions_Silent, "", lErrors, lWarnings)
    Set swModelDocExt = swModel.Extension
    Set swExportPDFData = swApp.GetExportFileData(1)

    ' Names of the sheets
    strSheetName(0) = "Sheet1"
    strSheetName(1) = "Sheet2"
    strSheetName(2) = "Sheet3"
    ' strSheetName(3) = "Sheet4"

    varSheetName = strSheetName

    If swExportPDFData Is Nothing Then MsgBox "Nothing"
    boolstatus = swExportPDFData.SetSheets(swExportData_ExportSpecifiedSheets, varSheetName)
    swExportPDFData.ViewPdfAfterSaving = True

    boolstatus = swModelDocExt.SaveAs(filename, 0, 0, swExportPDFData, lErrors, lWarnings)

End Sub



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Save File as PDF Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:



x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2015 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.