AnsweredAssumed Answered

Save drawing to PDF with date

Question asked by Zac Evans on Mar 23, 2016
Latest reply on Jan 11, 2018 by Timo Gulbinas

I have a macro that saves the current drawing to pdf in the same file location and the name of the drawing model, I'm new to macros and can't figure out how to have it save today's date to the end of the name (eg. 1234-567-8910 (3-23-16)) in the m-dd-yy format. here's the code I have for it.

 

Option Explicit

 

Dim FileName As String

Dim swExportPDFData As SldWorks.ExportPdfData

Dim swModel As SldWorks.ModelDoc2

Dim swApp As SldWorks.SldWorks

 

Sub main()

 

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

 

'Save Drawing

swModel.Save3 0, 0, 0

 

'Checks to make sure current file is a drawing

If swModel.GetType = swDocDRAWING Then

    'Gets current file name and path

    FileName = swModel.GetPathName

    'strips solidworks extension off name and replaces with pdf

    FileName = Left(FileName, Len(FileName) - 6) & "pdf"

    'message box line used to confirm modified file name

    'MsgBox FileName

    'sets current pdf export options

    Set swExportPDFData = swApp.GetExportFileData(1)

    'saves drawing as pdf

    swModel.Extension.SaveAs FileName, 0, 0, swExportPDFData, 0, 0

Else

    MsgBox "Current File is not a Drawing"

    End

End If

 

 

End Sub

Outcomes