AnsweredAssumed Answered

Can you add date to a folder created via a macro?

Question asked by Dave Baxter on Apr 24, 2020
Latest reply on Apr 26, 2020 by Dave Baxter

Is there a way of adding a date to a folder created with a macro that exports a drawing to .dwg and .pdf?


This is the code I am currently using. It works fine with the tweaks but I could do with either the date after the folder name (not the drawing names) or a number to show the latest (continuation number). It is mainly so it does not overwrite older conversions.



'PDF_DWG_ClientRelease_24-04-20'  or 'PDF_DWG_ClientRelease_01'  or similar?


Code below... (I have removed some of the text for clarity)


' Updated to set sub folder as Output folder for PDF/DWG files. Change as needed.

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim Filepath As String
Dim FileName As String
Dim boolstatus As Boolean
Dim longstatus As Long
Dim longwarnings As Long
Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
s = Format(Date, "mm-dd-yy")

' Check to see if a drawing is loaded.
If (swModel Is Nothing) Or (swModel.GetType <> swDocDRAWING) Then

swApp.SendMsgToUser ("To be used for drawings only, Open a drawing first and then TRY!")

' If no model currently loaded, then exit
Exit Sub

End If

Set swDraw = swModel
Filepath = Left(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "\"))

If Dir(Filepath & "PDF_DWG_ClientRelease", vbDirectory) = "" Then ' Change Sub folder Name here
MkDir Filepath + "PDF_DWG_ClientRelease\" ' Change Sub folder Name here
End If
Filepath = Filepath + "PDF_DWG_ClientRelease\" ' Change Sub folder Name here

FileName = Mid(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "\") + 1)
FileName = Left(FileName, Len(FileName) - 7)

swDraw.SaveAs (Filepath + FileName + ".PDF")
swDraw.SaveAs (Filepath + FileName + ".DWG")

MsgBox ("Files saved as DWG and PDF, see 'PDF_DWG_ClientRelease' folder" & vbCr & "Tweaked by DJB"), vbOKOnly, "by Deepak Gupta"

End Sub