AnsweredAssumed Answered

Help with a Macro

Question asked by Scott Littlejohn on Mar 19, 2015
Latest reply on Mar 23, 2015 by Brian Titus

I have a macro (shown below) that will generate a PDF from an active drawing, then close the drawing.  However, I have specific drawing templates where the third sheet is strictly for shop notes that I do not want to include in the PDF.  Is there a way to modify this code so that only the first two sheets are included in the PDF?



' ******************************************************************************

' MK-Library PDF Generator

' ******************************************************************************

' Create PDF of open drawing and then close drawing


Dim swApp As SldWorks.SldWorks

Dim Part As SldWorks.ModelDoc2


Sub main()


Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc

On Error Resume Next

Dim FilePath As String

Dim PathSize As Long

Dim PathNoExtension As String

Dim NewFilePath As String


FilePath = Part.GetPathName

PathSize = Strings.Len(FilePath)

PathNoExtension = Strings.Left(FilePath, PathSize - 6)

NewFilePath = PathNoExtension & "pdf"


  1. Part.SaveAs2 NewFilePath, 0, True, False


  1. swApp.ActiveDoc.ActiveView.FrameState = 1

Set Part = Nothing

  1. swApp.CloseDoc FilePath
  2. swApp.ActiveDoc.ActiveView.FrameLeft = 0
  3. swApp.ActiveDoc.ActiveView.FrameTop = 0
  4. swApp.ActiveDoc.ActiveView.FrameState = 1


End Sub