AnsweredAssumed Answered

Check if file is "in use" during Macro save

Question asked by jason kooken on May 5, 2016
Latest reply on Oct 3, 2016 by jason kooken

A am trying to Add warnings to my saving Macro

My new requirements are as follows:

1. I need a message box to alert user that one or both of the files to be saved are in use(locked)

2. I need to give the option to either retry or cancel from that message

 

Thanks in advance for any help.

below is the working code I have to this point:

 

 

 

Dim longstatus As Long, longwarnings As Long

Dim swModel As SldWorks.ModelDoc2

Dim swApp As SldWorks.SldWorks

 

 

Sub main()

    Set swApp = Application.SldWorks

    Set Part = swApp.ActiveDoc

    Set swModel = swApp.ActiveDoc

    Set SelMgr = Part.SelectionManager

    Dim proj As String

    Dim dwg As String

    Dim filename As String

    Dim saveLoc As String

    Dim rev As String

    Dim trueRev As String

    Set swCusPropMgr = swModel.Extension.CustomPropertyManager("")

 

    filename = swModel.GetPathName

    If filename = "" Then

        MsgBox "Please save the file first and try again", vbCritical

        End

    End If

  

'Get Revision

    retval = swCusPropMgr.Get3("Revision", False, rev, trueRev)

    If rev = "-" Then

        rev = ""

    End If

 

    dwg = Strings.Left(filename, Len(filename) - 7)

    proj = Strings.Left(dwg, 4)

  

'Filepath

        dwg = Strings.Right(dwg, 8)

        proj = Strings.Left(dwg, 4)

        Part.Extension.SaveAs "\\xxxxxxx\DWGS\" + proj + "\" + dwg + rev + ".PDF", 0, 0, Nothing, longstatus, longwarnings

        Part.Extension.SaveAs "\\xxxxxxx\DWGS\" + proj + "\" + dwg + rev + ".EDRW", 0, 0, Nothing, longstatus, longwarnings

End Sub

 

Message was edited by: jason kooken

Outcomes