7 Replies Latest reply on Mar 1, 2017 9:20 AM by Ulf Nutti

    Save certain sheet with NCP in the sheetname as .DWG

    Roger Chee

      Hi all,

       

      I'm looking for some help to modify a code that that saves certain sheets of my drawings into PDF.

      I need the macro to export sheets in my drawings that contain "NCP" in the sheetname as .DWG

      Right now, I have the macro to save the exported files to my desktop.

      Below is the code that I need help with modifying:

       

      Option Explicit

       

      Sub main()

       

       

          Dim swApp               As SldWorks.SldWorks

          Dim swModel             As SldWorks.ModelDoc2

          Dim swDrawDoc           As SldWorks.DrawingDoc

          Dim swModelDocExt       As SldWorks.ModelDocExtension

          Dim swExportPDFData     As SldWorks.ExportPdfData

          Dim boolstatus          As Boolean

          Dim filename            As String

          Dim lErrors             As Long

          Dim lWarnings           As Long

          Dim strSheetName()      As String

          Dim varSheetName        As Variant

       

          ' Path to which to save PDF file of drawing (I need this to be in DWG format)

          filename = "C:\xxxxxxxxx.PDF"

         

          Set swApp = Application.SldWorks

          swApp.Visible = True

       

          Set swModel = swApp.ActiveDoc

          Set swDrawDoc = swModel

          Set swModelDocExt = swModel.Extension

       

          Set swExportPDFData = swApp.GetExportFileData(swExportDataFileType_e.swExportPDFData)

         

          ReDim strSheetName(0)

          Dim s As Variant

          For Each s In swDrawDoc.GetSheetNames

              If UCase(s) Like "*NCP*" Then

                  strSheetName(UBound(strSheetName)) = s

                  ReDim Preserve strSheetName(UBound(strSheetName) + 1)

              End If

          Next s

         

          varSheetName = strSheetName

          If swExportPDFData Is Nothing Then MsgBox "Nothing"

          boolstatus = swExportPDFData.SetSheets(swExportData_ExportSpecifiedSheets, varSheetName)

         

      boolstatus = swModelDocExt.SaveAs(filename, 0, 0, swExportPDFData, lErrors, lWarnings)

       

      End Sub