SOLVED!Read Only Macro ?

ROBINSYN

Board Regular
Joined
Aug 19, 2002
Messages
188
Is there a macro so I can set a file to read only before close?
This message was edited by ROBINSYN on 2002-11-10 21:45
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
On 2002-10-27 21:03, ROBINSYN wrote:
Is there a macro so I can set a file to read only before close?

While in the VBA Editor press F1
Type in Readonly > you should get what you need from the help...
 
Upvote 0
Sub SetReadOnly()
'Run from Standard Module.
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
'You must add your Drive, Folder and File Name below to run this.
Set f = fs.GetFile(fs.GetFileName("C:MyFilesExcelTestMyReadOnlyMacro.xls"))
f.Attributes = f.Attributes + 1
End Sub
 
Upvote 0
On 2002-10-27 21:03, ROBINSYN wrote:
Is there a macro so I can set a file to read only before close?

Hi !

Here is an alternative way to set the "ReadOnly" property for the file in use;


Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
SetAttr ThisWorkbook.Path & "" & ThisWorkbook.Name, vbReadOnly
End Sub
This message was edited by Raider on 2002-10-28 02:27
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top