Hi all
I got a macro on the forum to save my Solidworks MEPs in PDF, my problem is that the macro changes the name of the PDF and I wouldn't like that.
I've already deleted the lines I don't need, but it's not good yet...
Could someone please modify the macro so that the file name remains like the MEP, I would like to keep the 2 save locations.
The macro:
' We define the necessary variables
Dim swApp As Object
Dim swModel As SldWorks.ModelDoc2
Dim swCustProp As CustomPropertyManager
Dim valOut1 As String
Dim valOut2 As String
Dim valOut3 As String
Dim resolvedValOut1 As String
Dim resolvedValOut2 As String
Dim resolvedValOut3 As String
Dim Path As String
Dim PathDesktop As String
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swExportPDFData As SldWorks.ExportPdfData
Dim nFileName As String
Dim nFileName2 As String
Dim boolstatus As Boolean
Dim lErrors As Long
Dim lWarnings As Long
Dim lgFile As Integer
Sub main()
' We cling to Solidworks
Set swApp = Application.SldWorks
' We retrieve the active document in Solidworks
Set swModel = swApp.ActiveDoc
' We check that a document is open in Solidworks
If swModel Is Nothing Then
MsgBox "A document must be active in Solidworks.", vbCritical
End
End If
' We verify that the document opened in Solidworks is a plan
If swModel.GetType <> swDocDRAWING Then
MsgBox "The active document in Solidworks must be a plan.", vbCritical
End
End If
' We check that the open plan in Solidworks is saved
If swModel.GetPathName = "" Then
swModel.Save
End If
' We retrieve the path of the plan registration folder
Path = swModel.GetPathName
lgFile = InStrRev(Path, "\", -1, vbTextCompare) - 1
If lgFile > 0 Then
Path = Left(Path, lgFile)
End If
' We recover the path of the Windows desktop
PathDesktop = About("USERPROFILE") & "\Desktop"
' We define the export parameters in PDF
Set swModelDocExt = swModel.Extension
Set swExportPDFData = swApp.GetExportFileData(1)
swExportPDFData.ViewPdfAfterSaving = False
' We define the path and the name of the first pdf file to be created
nFileName = Path & "\" & resolvedValOut1 & " - " & resolvedValOut2 & " - Ind." & resolvedValOut3 & " - " & dateNow & ".PDF"
' Save the first pdf file
boolstatus = swModelDocExt.SaveAs(nFileName, 0, 0, swExportPDFData, lErrors, lWarnings)
' We define the path and the name of the second pdf file to be created
nFileName2 = PathDesktop & "\" & resolvedValOut1 & " - " & resolvedValOut2 & " - Ind." & resolvedValOut3 & " - " & dateNow & ".PDF"
' We save the second pdf file
boolstatus = swModelDocExt.SaveAs(nFileName2, 0, 0, swExportPDFData, lErrors, lWarnings)
End Sub
Thank you in advance.