AnsweredAssumed Answered

Change Path on save to PDF VBA Macro

Question asked by Michael Ortíz on Jan 9, 2020
Latest reply on Jan 20, 2020 by Michael Ortíz

Hello,

 

I am trying to use a pre-made macro created by Deepak Gupta  to save my multi sheet drawing as individual pdf files.  The macro is working great except that I need to customize the path where the pdf files are being saved.  I don't have much experience in writing macros and have been digging around the forums and online trying to uncover which part of this macro is designating the "save to" location.  I would like to assign my own location but don't see how.  Below is the code from the macro.  Thanks in advance for your help.

 

Regards,

Mike

 

 

'Export Drawing Sheets As PDF.swp ------------- 10/19/12

 

'Description: Macro to export Drawing Sheets As PDF with sheet name as file name.

 

'Precondition: Any active drawing file

 

'Postconditions: PDF file in the same location as drawing file.

 


' Please back up your data before use and USE AT OWN RISK

 

' This macro is provided as is.  No claims, support, refund, safety net, or
' warranties are expressed or implied.  By using this macro and/or its code in
' any way whatsoever, the user and any entities which the user represents,
' agree to hold the authors free of any and all liability.  Free distribution
' and use of this code in other free works is welcome.  If any portion of
' this code is used in other works, credit to the authors must be placed in
' that work within a user viewable location (e.g., macro header).  All other
' forms of distribution (i.e., not free, fee for delivery, etc) are prohibited
' without the expressed written consent by the authors.  Use at your own risk!
' ------------------------------------------------------------------------------
' Written by: Deepak Gupta (http://gupta9665.wordpress.com/)
' -----------------------------------------------------------------------------

 

Sub main()

 

Dim swApp                   As SldWorks.SldWorks
Dim swModel                 As SldWorks.ModelDoc2
Dim swDraw                  As SldWorks.DrawingDoc
Dim swSheet                 As SldWorks.Sheet
Dim vSheetNameArr           As Variant
Dim vSheetName              As Variant
Dim bRet                    As Boolean
Dim swExportPDFData         As SldWorks.ExportPdfData
Dim lErrors                 As Long
Dim lWarnings               As Long

 

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

 

' Is document active?

 

If swModel Is Nothing Then

 

    swApp.SendMsgToUser2 "A Drawing document must be active.", swMbWarning, swMbOk

 

    Exit Sub

 

End If
 

 

' Is it a Drawing document?

 

If swModel.GetType <> swDocDRAWING Then

 

    swApp.SendMsgToUser2 "A Drawing document must be active.", swMbWarning, swMbOk

 

    Exit Sub

 

End If

 


Set swDraw = swModel
Set swSheet = swDraw.GetCurrentSheet

 

vSheetNameArr = swDraw.GetSheetNames
For Each vSheetName In vSheetNameArr

 

bRet = swDraw.ActivateSheet(vSheetName): Debug.Assert bRet

 

swDraw.ViewZoomtofit2

 

Set swExportPDFData = swApp.GetExportFileData(1)
swExportPDFData.SetSheets swExportData_ExportSpecifiedSheets, vSheetName
swModel.Extension.SaveAs vSheetName + ".PDF", 0, 0, swExportPDFData, lErrors, lWarnings

 

Next vSheetName

 

End Sub

Outcomes