Friday, May 04, 2007

Changing File Attributes

SetAttr Function - Modifying File Atrributes

Sub Changing_File_Attributes()

' Using the SetAttr Function, We can set the file as read-only or hidden etc

' Make the file Read-Only
SetAttr "c:\temp\Sample.txt", vbReadOnly

' Make the file Hidden
SetAttr "c:\temp\Sample.txt", vbHidden

' Please note that if you change one attribute, the existing attribute is overwritten. For making a file as both readonly and hidden use both attributes in the function
SetAttr "c:\temp\Sample.txt", vbHidden + vbReadOnly

' Remove all atributes - convert a read-only file to read-write file, unhide the file etc
SetAttr "c:\temp\Sample.txt", vbNormal

End Sub


  1. Anonymous5:28 PM

    set to read only, on-off (re: attribute set)

    SetAttr "c:\temp\Sample.txt", vbReadOnly + vbArchive
    SetAttr "c:\temp\Sample.txt", vbArchive

  2. Anonymous4:02 PM

    i need for it to turn readonly OFF to write to file then turn readonly ON

  3. Perfect! ou can, in fact, define a string variable like so :
    ActiveWorkbook.SaveAs Filename:=Path & name1 & "-" & mydate & ".xlsx", FileFormat:=51
    myfilename = ActiveWorkbook.FullName
    SetAttr myfilename, vbReadOnly

  4. Anonymous12:40 AM

    Hi, thank you for this post.
    Is there any way to get or set other attributes like Title , or Description or tags? I'm working with jpg files.

    1. Anonymous10:24 PM

      Extract JPEG / JPG file property using VBA -


Share on Facebook
Related Posts Plugin for WordPress, Blogger...
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.