> Save File as PDF Example (VBA)
Welcome
Getting Started
SolidWorks API Help
FeatureWorks API Help
SolidWorks Document Manager API Help
eDrawings API Help
SolidWorks Routing API Help
SolidWorks Simulation API Help
SolidWorks Utilities API Help
SolidWorks Workgroup PDM API Help
Hide Table of Contents Show 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: The specified drawing document exists.

'

'                NOTE: The drawing document is installed when

'                      you install SolidWorks.

'

' Postconditions: The specified sheet is exported to a PDF file.

'------------------------------------------------------------------

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\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)

    

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:  
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) 2011 SP05

The search functionality within the web help is in a beta test phase and you may experience periodic delays or interruptions in its performance. These are the normal and ordinary features of a beta test and shall not under any circumstances give rise to any liability on the part of Dassault Systèmes SolidWorks Corporation or its licensors. The topics within the Web-based help are not beta topics; they document API Help (English only) 2011 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.