![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Mar 2002
Posts: 11
|
Hi,
Is there a way to save the xls file as read-only format, using VB? Thanks /dan |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
|
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) |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
|
Yes there is : ReadOnlyRecommended:=True
code example Code:
ActiveWorkbook.SaveAs Filename:="C:Book1.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=True, CreateBackup:=False
|
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
|
Nimrod, that only "suggests" the user to open it as read-only, they still can say, "no", to open it normally !
|
|
|
|
|
|
#5 |
|
New Member
Join Date: May 2002
Posts: 9
|
Click right on the file name and choose "read only"
|
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Jan 2005
Posts: 140
|
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... |
|
|
|
|
|
#7 |
|
New Member
Join Date: Mar 2002
Location: Leicestershire, England
Posts: 48
|
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 |
|
|
|
|
|
#8 |
|
New Member
Join Date: Feb 2011
Location: Norfolk, UK
Posts: 19
|
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 |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|