Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

  2. #2
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

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

    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. Have fun! --Sam
    <pre>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</pre>

    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  3. #3
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

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

    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

  4. #4
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    Andrew,

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

    Troy

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

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

    shell("attrib +r ""pathfilename.ext""")
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •