Hi all
I currently have a macro that allows me to save my .slddrw document in pdf under the same directory and the same name.
So far so good, the problem is that it saves all the sheets of my drawing and I want it to save me only the active sheet when I launch my macro.
I'm sure the solution is simple but nothing to do I can't find the right code, here is the macro I got from the forum and that I use:
'**************************************************************************************************************************
'* Example of a macro that allows you to save documents as PDFs
'* You can Change the extension to save the document in any format supported by SW
'* Based on the example made by Axemble "Saveas_pdf"
'* Edit by MCD
'**************************************************************************************************************************
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swmodel As SldWorks.ModelDoc2
Dim stPath As String
Dim lgFile As Long
Dim blretval as Boolean
Dim Errors As Long
Dim Warnings As Long
Set swApp = Application.SldWorks
'We get the active document
Set swmodel = swApp.ActiveDoc
If Not Swmodel Is Nothing Then
'We check that the file is registered
If swmodel. GetPathName = "" Then
MsgBox "Please save your document before launching the macro", vbInformation
End
Else
'we get the location of the file
stPath = swmodel. GetPathName
'we get the number of characters up to . of the extension
lgFile = InStrRev(stPath, ".", -1, vbTextCompare) - 1
'we recover the path without the extension
If lgFile > 0 Then
stPath = Left(stPath, lgFile)
End If
End If
'If the document is a document
If swmodel. GetType = swDocPART Then
We create the developed
'blretval = swmodel. ExportFlatPatternView(stPath & ". DXF", 1)
The DXF was created
'blretval = swmodel. SaveAs3(stPath & ". DXF", 0, 0)
MsgBox "This is a Piéce file. Open the drawing to make the PDF", vbInformation
'If the document is a drawing
ElseIf swmodel. GetType = swDocDRAWING Then
The DXF was created
'blretval = swmodel. SaveAs3(stPath & "_drw.pdf", 0, 0)
Create the PDF
blretval = swmodel. SaveAs3(stPath & ".pdf", 0, 0)
End If
'we save the file
blretval = swmodel. Save3(0, 0, 0)
End If
End Sub