save file as read only

danclemson

New Member
Joined
Mar 13, 2002
Messages
11
Hi,

Is there a way to save the xls file as read-only format, using VB?

Thanks /dan
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
There's a function in VBA, called

SetAttr(PathName as String,Attributes as VbFileAttribute)

which you can use to set the attributes to a file (It has to be closed, if I'm correct)
 
Upvote 0
Yes there is : ReadOnlyRecommended:=True

code example
Code:
ActiveWorkbook.SaveAs Filename:="C:Book1.xls", _
        FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=True, CreateBackup:=False

This one is an easy one to find out... just start your macro recorder, save a file and you will get the code needed.
 
Upvote 0
i am also trying to use vba to save a file as read only. is there another method beyond the two listed?

1. set file attributes
problem - i'll have to save the file to the new name, close the file, set it to read only, reopen the file, and then close the active workbook.

2. set readonlyrecommeded attribute
problem - this will still let someone open the file as read only...
 
Upvote 0
Save

Hi

I've also been trying to save a file as read only. I currently have a macro which range values the data in a master file, and saves the file down in a location that the recipients can access. The problem I had was that sometimes a user was already in the (range valued) file, and my save macro falls over when attempting to save with the same name.

The only way I've managed to get round this is to save the file with a read/write protect password (via a macro).

Not ideal, but it works. Hope this helps. See below.

Application.DisplayAlerts = False

ActiveWorkbook.SaveAs Filename:="S:\Report\0708\DailySales\SaveTest.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="test", _
ReadOnlyRecommended:=False, CreateBackup:=False
 
Upvote 0
Hi all,

Just bumping this up, as I have a similar problem, and wondered if anyone knew of a better way than suggested with the WriteResPassword suggestion, which does work, but I don't really want to password protect the file.

Any ideas would, as always, be gladly accepted.

Cheers,

Lotus Cars
 
Upvote 0

Forum statistics

Threads
1,214,578
Messages
6,120,361
Members
448,956
Latest member
Adamsxl

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