ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
ZEZac Evans23/03/2016

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