3 Replies Latest reply on Jun 14, 2014 11:43 AM by Deepak Gupta

    SW macro to toggle a SW files windows read only attribute

    Grant Baugh

      Is it possible to have a SW macro to toggle a SW files windows read only  attribute?  Basically can a macro check and uncheck the read only state  in Windows?  We keep our fasteners as read only in Windows but  occasionally we have to edit them so we have to browse to the file right  click and uncheck "read only".  When done editing we have to recheck  "read only".  Trying to condense that down to only having to click a  macro once we have the file open.

        • Re: SW macro to toggle a SW files windows read only attribute
          Ivana Kolin

          yes it is possible

           

          you can use vba statement SetAttr

           

           

          SetAttr "TESTFILE", vbHidden ' Set hidden attribute.

           

           

          ' Set hidden and read-only

          ' attributes.

          SetAttr "TESTFILE", vbHidden + vbReadOnly

           

           

           

           

          or  Scripting.FileSystemObject

           

          Function MakeFileReadOnly(ByVal sFile As String)

             

              Dim strSaveFilename As String

              Dim oFSO As Object

             

              'Scripting.FileSystemObject Dim oFile As Object

              'Scripting.File

              ' Create Objects

              ' Uses Late Binding

             

              Set oFSO = CreateObject("Scripting.FileSystemObject")

              Set oFile = oFSO.GetFile(FilePath:=sFile)

              'Set file to be read-only

             

              oFile.Attributes = 1

              ' Releasing Objects

              If Not oFSO Is Nothing Then Set oFSO = Nothing

              If Not oFile Is Nothing Then Set oFile = Nothing

           

           

          End Function

          • Re: SW macro to toggle a SW files windows read only attribute
            Deepak Gupta

            Yes it can b e done but the file will have to be closed IMO to set the attributes from readonly to normal and then back to readonly.

             

            With that said, it all can be done via a macro i.e. once you activate the file (make it current active file) and run the macro. Then macro would close it, remove readonly and open it again. You make the changes and then macro will close it, set to readonly and open again. I should mention that macro would keep running in the background and would wait until you close it to process further.