Hello
I created a macro using what I found, it must convert my MEP to pdf and save it in the folder of the year in which it was created, if the folder does not exist the create.
There she is:
Dim swApp As Object
Dim Part As Object
Dim FileNamePDF As String
Sub main()
Dim swApp As SldWorks.SldWorks
Dim SWmoddoc As SldWorks.ModelDoc2
Sun NumberPlan As String
Dim PathFile As String
Dim FileName As String
Dim NumberLeaf As String
Dim FileNamePDF As String
Dim PathFileNamePDF As String
Dim NameFolderPDF As String
Dim nErrors As Long
Dim nWarnings As Long
Set swApp = Application.SldWorks
Set SWmoddoc = swApp.ActiveDoc
'Retrieving the path and filename
Example: \\MERCURE\Sharing\xMethods\Public\DAO\Solidworks\2 - Drawing\2014\046-1-2014-A.SLDDRW
PathName = SWmoddoc.GetPathName
FilePath = Left(PathName, InStrRev(PathName, "\")) '\\MERCURY\Sharing\xMethods\Public\DAO\Solidworks\2 - Drawing\2014\
FileName = Right(PathName, Len(PathName) - InStrRev(PathName, "\")) '046-1-2014-A.SLDDRW
FileNamePDF = Right(FileName, 13) '2014-A.SLDDRW
FileNamePDF = Left(FileNamePDF, 4) '2014
FileNamePathPDF = "\\MERCURY\Sharing\xMethods\Public\DAO\PDF Plans\" & FolderNamePDF '\\MERCURY\Sharing\xMethods\Public\DAO\PDF Plans\2014\
'------------------------------------------------------------------
'Retrieving custom properties from the plan file
If SWmoddoc.GetType = swDocDRAWING Then check that we are on a plan file
FileNamePDF = Replace(FileName, "SLDDRW", "pdf")
End If
'------------------------------------------------------------------
'Test if the folder with the year exists, if not create it
If Dir$(FileNamePathPDF) = "" Then
MkDir "FileNamePDF"
End If
'------------------------------------------------------------------
'Test if the file already exists or confirm
'then recording
If Dir$(FileNamePathPDF) = FileNamePDF Then 'The file already exists
If MsgBox("The file: " & FileNamePDF & vbNewLine & " already exists. Do you want to replace him?", _
vbOKCancel + vbExclamation) = vbOK Then
nErrors = SWmoddoc.SaveAs(FileNamePathPDF)
Else
If MsgBox("PDF file was not created.", vbInformation) = vbOK Then Exit Sub '-------Message and EXIT-------
End If
Else
If MsgBox("File: " & FileNamePDF & vbNewLine & " Is Going to Be Created", vbOKCancel + vbInformation) = vbOK Then
nErrors = SWmoddoc.SaveAs(FileNamePathPDF)
Else
If MsgBox("PDF file was not created.", vbInformation) = vbOK Then Exit Sub '-------Message and EXIT-------
End If
End If
End Sub
I don't know how to test it and I would like to know before launching it if I haven't done something stupid because it plays with the folders of my company's network.
Thank you in advance.