AnsweredAssumed Answered

Save as Pdf - file overwrite

Question asked by Feroz Mahomed on Nov 2, 2019
Latest reply on Nov 2, 2019 by Feroz Mahomed

What code do i add below to warn me that the file already exists before overwriting the file?

 

    Option Explicit

 

    Dim swApp           As SldWorks.SldWorks

 

    Dim swModel         As SldWorks.ModelDoc2

 

    Dim swDraw          As SldWorks.DrawingDoc

 

    Dim swCustProp      As CustomPropertyManager

 

    Dim valOut          As String

 

    Dim resolvedValOut  As String

 

    Dim Filepath        As String

 

    Dim FileName        As String

 

    Dim swView          As SldWorks.View

 

     

 

    Sub main()

 

    Set swApp = Application.SldWorks

 

    Set swDraw = swApp.ActiveDoc

 

     

 

    ' Check to see if a drawing is loaded.

 

    If (swDraw Is Nothing) Or (swDraw.GetType <> swDocDRAWING) Then

 

    swApp.SendMsgToUser ("To be used for drawings only, Open a drawing first and then TRY!")

 

    ' If no model currently loaded, then exit

 

    Exit Sub

 

    End If

 

     

 

    Set swView = swDraw.GetFirstView

 

    Set swView = swView.GetNextView

 

    Set swModel = swView.ReferencedDocument

 

     

 

   ' Set swCustProp = swModel.Extension.CustomPropertyManager("")

 

   ' swCustProp.Get2 "Revision", valOut, resolvedValOut 'Change the custom property name here

 

    

 

    'Filepath = "C:\scans" ' Change File Path here

 

   Filepath = "v:\Die Correction\Midrand Transfers\Solids"
    Filepath = Filepath + "\"

 

     

 

    If Dir(Filepath) = "Die Correction\Midrand Transfers\Solids" Then

 

            MkDir Filepath

 

    End If

 

     

 

    FileName = Mid(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "\") + 1)

 

    FileName = Left(FileName, InStrRev(FileName, ".") - 1)

 

     

 

    swDraw.SaveAs (Filepath + FileName + "" + resolvedValOut + ".PDF") 'Change the custom property text here

 

     

 

    End Sub

Outcomes