Hide Table of Contents

Save Document As TIFF Example (VBA)

This example shows how to:

  • Set TIFF export options

  • Save the active document to a .tif format in the same directory as the model document.

'------------------------------------------------------------------
' Preconditions:
' 1. Open a model document.
' 2. Open the Immediate window.
'
' Postconditions:
' 1. Gets TIFF settings.
' 2. Saves the model document as a TIFF file to the same folder as
'    the model document and overwrites any existing file of the same name
'    in that folder.
' 3. Examine the Immediate window and the folder where the TIFF file
'    was saved.
'------------------------------------------------------------------
Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim sPathName As String
    Dim nRetVal As Long
    Dim nErrors As Long
    Dim nWarnings As Long
    Dim bRe As Boolean
    Set swApp = CreateObject("SldWorks.Application")
    Set swModel = swApp.ActiveDoc
    ' Get current TIFF settings
    Debug.Print "PrintScaleToFit        = " + Str(swApp.GetUserPreferenceToggle(swTiffPrintScaleToFit))
    Debug.Print "ScreenOrPrintCapture   = " + Str(swApp.GetUserPreferenceIntegerValue(swTiffScreenOrPrintCapture))
    Debug.Print "ImageType              = " + Str(swApp.GetUserPreferenceIntegerValue(swTiffImageType))
    Debug.Print "CompressionScheme      = " + Str(swApp.GetUserPreferenceIntegerValue(swTiffCompressionScheme))
    Debug.Print "PrintDPI               = " + Str(swApp.GetUserPreferenceIntegerValue(swTiffPrintDPI))
    Debug.Print "PrintPaperSize         = " + Str(swApp.GetUserPreferenceIntegerValue(swTiffPrintPaperSize))
    Debug.Print "PrintScaleFactor       = " + Str(swApp.GetUserPreferenceIntegerValue(swTiffPrintScaleFactor))
    Debug.Print "DrawingPaperHeight     = " + Str(swApp.GetUserPreferenceDoubleValue(swTiffPrintDrawingPaperHeight))
    Debug.Print "DrawingPaperWidth      = " + Str(swApp.GetUserPreferenceDoubleValue(swTiffPrintDrawingPaperWidth))
    ' Strip off SOLIDWORKS file name extension (sldprt, sldasm, or slddrw)
    ' and add TIFF extension (tif)
    sPathName = swModel.GetPathName
    sPathName = Left(sPathName, Len(sPathName) - 6)
    sPathName = sPathName + "tif"
    Debug.Print sPathName
    bRet = swModel.SaveAs4(sPathName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, nErrors, nWarnings)
    If bRet = False Then
        nRetVal = swApp.SendMsgToUser2("Problems saving file.", swMbWarning, swMbOk)
    End If
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 Document as TIFF 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) 2019 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.