• Checking & Changing ReadOnly Prop. 4 Closed File (Word 2000)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Checking & Changing ReadOnly Prop. 4 Closed File (Word 2000)

    Author
    Topic
    #379449

    Is there any easy way to determine if a closed file is read only (i.e. what you can see by right-clicking in Windows Explorer and clicking properties)?

    I’d also like to be able to change that property.

    I’d guess there is some API call out there that should do the trick if nothing else.

    Thanks for the help!!
    Troy

    Viewing 1 reply thread
    Author
    Replies
    • #631938

      You can use the FileSystemObject. Be use to use the Tools | References menu to add a reference to Microsoft Scriptin Runtime. There is a problem with the help file for the FileSystemObject, but it is on-line at http://msdn.microsoft.com/library/default….jFileSystem.asp[/url]. Have fun! –Sam

      Option Explicit
      
      Sub removeReadOnly()
      ' Add a reference to Microsoft Scriptin Runtime
      Dim fso As New Scripting.FileSystemObject
      Dim f As Scripting.File
      Const fsoNORMAL = 0, fsoREADONLY = 1
      Dim s As String
      Dim rsp As Integer
          s = Dir("*.doc")
          Do While s  ""
              Set f = fso.GetFile(s)
              If f.Attributes And fsoREADONLY Then
                  rsp = MsgBox("Reset attributes of " & s & " to normal?", vbYesNo)
                  If rsp = vbYes Then _
                      f.Attributes = f.Attributes And (Not fsoREADONLY)
              End If
              s = Dir()
          Loop
          Set f = Nothing
          Set fso = Nothing
      End Sub
    • #631947

      Your API call would be :

      Declare Function SetFileAttributes Lib “kernel32” _
      Alias “SetFileAttributesA” ( _
      ByVal lpFileName As String, _
      ByVal dwFileAttributes As Long) As Long

      then use

      Result = SetFileAttributes(“Path:Filename”,&H80)

      to set the attribute to Normal.

      &H1 would set the file to read only.

      Andrew C

      • #631964

        Andrew,

        Simple is better!! Thanks for the simple solution!!

        Troy

        • #631970

          Well, here’s simple, but not necessarily better:

          shell(“attrib +r “”pathfilename.ext”””)

    Viewing 1 reply thread
    Reply To: Checking & Changing ReadOnly Prop. 4 Closed File (Word 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: