ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
MTMarko Topalovic17/10/2018

Hi,

I have been using a macro I found in this forum to export each sheet as a separate file. This macro is working fine but the "problem" we have when we are using this macro is that filename is generated as "filename - sheetname.extension" and for our needs we have to save the files as "sheetname - filename.extension". the reason behind this is that we have to place SAP code in front of everything to be visible.

I have tried to modify the macrto for our needs but I am amateur in programming and I can not find the line in code where I can change the order of the generated file name.

Can someone please tell me how can I modify this code? Also, can I implement custom property in this code?

code:

Option Explicit

Dim swApp               As SldWorks.SldWorks

Dim swModel             As SldWorks.ModelDoc2

Dim swModelDocExt       As SldWorks.ModelDocExtension

Dim swExportPDFData     As SldWorks.ExportPdfData

Dim swDraw              As SldWorks.DrawingDoc

Dim swSheet             As SldWorks.Sheet

Dim boolstatus          As Boolean

Dim sFilename           As String

Dim lErrors             As Long

Dim lWarnings           As Long

Dim strSheetName(20)    As String

Dim varSheetName        As Variant

Dim varSheetCount       As Variant

Dim i                   As Long

Private Sub cboFileExt_Change()

End Sub

Private Sub cmdSave_Click()

On Error GoTo error

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swDraw = swApp.ActiveDoc

If swModel.gettype <> 3 Then

    MsgBox "Open Document is not a Drawing file.", vbCritical, "Wrong Document Type Open"

End If

Set swModelDocExt = swModel.Extension

Set swExportPDFData = swApp.GetExportFileData(1)

varSheetCount = swModel.GetSheetCount()

For i = 1 To varSheetCount

    swDraw.SheetPrevious

Next i

For i = 0 To varSheetCount - 1

    If i <> 0 Then

        swDraw.SheetNext

    End If

    Set swSheet = swDraw.GetCurrentSheet

    strSheetName(i) = swSheet.GetName

    Set swSheet = Nothing

   

    varSheetName = strSheetName(i)

   

    sFilename = swModel.GetTitle & "." & frmMain.cboFileExt.Text

    If swExportPDFData Is Nothing Then MsgBox "Nothing"

    boolstatus = swExportPDFData.SetSheets(swExportData_ExportSpecifiedSheets, varSheetName)

   

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

Next i

Unload frmMain

Exit Sub

error:

MsgBox "An error has occured - Please close and reopen SolidWorks to try again", vbCritical, "Program Error"

Exit Sub

End Sub