AnsweredAssumed Answered

How to save the drawing PDF in a folder using VBA macro?

Question asked by Mohammed Shuaib on Feb 22, 2021
Latest reply on Feb 23, 2021 by Peter Brinkhuis



I want to save the drawing PDF in the file location into a folder called "PDF" using VBA macro.


I am using the below code but its getting saved in the file location itself:

Sub main()

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swExportPDFData As SldWorks.ExportPdfData
Dim strFilename As String
Dim status As Boolean
Dim errors As Long, warnings As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc


status = swModel.Save3(swSaveAsOptions_e.swSaveAsOptions_Silent, errors, warnings)


If (swModel.GetType = swDocDRAWING) Then
strFilename = swModel.GetPathName
strFilename = Left(strFilename, Len(strFilename) - 6) & "pdf"

Set swExportPDFData = swApp.GetExportFileData(1)
swModel.Extension.SaveAs strFilename, 0, 0, swExportPDFData, 0, 0

End If

End Sub


Please help me with the code.




Mohammed Shuaib