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
Friday, May 04, 2007
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.
set to read only, on-off (re: attribute set)
ReplyDeleteSetAttr "c:\temp\Sample.txt", vbReadOnly + vbArchive
SetAttr "c:\temp\Sample.txt", vbArchive
i need for it to turn readonly OFF to write to file then turn readonly ON
ReplyDeletePerfect! ou can, in fact, define a string variable like so :
ReplyDeleteActiveWorkbook.SaveAs Filename:=Path & name1 & "-" & mydate & ".xlsx", FileFormat:=51
myfilename = ActiveWorkbook.FullName
SetAttr myfilename, vbReadOnly
Hi, thank you for this post.
ReplyDeleteIs there any way to get or set other attributes like Title , or Description or tags? I'm working with jpg files.
Extract JPEG / JPG file property using VBA - https://social.msdn.microsoft.com/Forums/en-US/471d0987-ed1e-438e-a561-9ce05c36a01f/getting-file-properties-for-a-file-in-excel-vba?forum=isvvba
Delete