AnsweredAssumed Answered

Compile error: Type mismatch

Question asked by Roni Ampuja on May 24, 2018
Latest reply on May 31, 2018 by Roni Ampuja

Option Explicit

    Dim swApp               As SldWorks.SldWorks

    Dim swModel             As SldWorks.ModelDoc2

    Dim swModelDocExt       As SldWorks.ModelDocExtension

    Dim swExportData        As SldWorks.ExportPdfData

    Dim boolstatus          As Boolean

    Dim filename            As String

    Dim lErrors             As Long

    Dim lWarnings           As Long

    Dim amountSaved         As Object

   

 

 

Sub main()

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set amountSaved = 0

    If swModel Is Nothing Then

        MsgBox "Ei Olemassa Olevaa Tiedostoa", vbCritical

        End

    End If

    If swModel.GetType <> swDocDRAWING Then

        MsgBox "Tämä Macro Toimii Vain Työkuva Näkymässä", vbCritical

        End

    End If

    Set swModelDocExt = swModel.Extension

    Set swExportData = swApp.GetExportFileData(swExportPdfData)

    filename = swModel.GetPathName

    If filename = "" Then

        MsgBox "Tallenna Tiedosto ensin ja kokeile uudestaan", vbCritical

        End

    End If

   

    'Save drawing

    boolstatus = swExportData.SetSheets(swExportData_ExportAllSheets, 1)

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

    If boolstatus Then

        amountSaved += 1

    Else

        MsgBox "Työkuvan Tallennus Epäonnistunut, Error code:" & lErrors

    End If

   

   

    'Save as PDF

    filename = Strings.Left(filename, Len(filename) - 6) & "PDF"

    boolstatus = swExportData.SetSheets(swExportData_ExportAllSheets, 1)

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

    If boolstatus Then

        amountSaved += 1

    Else

        MsgBox "PDF Tallennus Epäonnistunut, Error code:" & lErrors

    End If

 

 

    'Save as DXF

    filename = Strings.Left(filename, Len(filename) - 3) & "DXF"

    boolstatus = swExportData.SetSheets(swExportData_ExportAllSheets, 1)

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

    If boolstatus Then

        amountSaved += 1

    Else

        MsgBox "DXF Tallennus Epäonnistunut, Error code:" & lErrors

    End If

   

    MsgBox amountSaved & " tiedoston tallennus onnistui"

End Sub

 

 

 

 

On the line: Set amountSaved = 0      I get Compile error: Type mismatch.

 

Im trying to make macro that saves drawing and dxf and pdf. And then informs if saving of all those was succesfull but I can't get over this error.

Outcomes