Make File Read Only in VBA Excel
Sub sbMakeFileReadOnly()
Dim strSaveFilename As String
Dim oFSO As Object
Dim oFile As Object
sFile = "C:\ExampleFile.xls" 'Your File name and Path to make it read only
'Create Objects
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 Sub
No comments:
Post a Comment