Save as read only

csilabgirl

Active Member
Joined
Aug 14, 2009
Messages
359
Excel 2002

I have this code which is saving a workbook. I want it to save the workbook as read only, so that the next time it is opened it is read only. But all I have been able to do is a read only recommend, where the next time it is opened it asks the user if they want to open it in read only or not. I dont want them to have the option. What do I need to add to my code? Thank you for the help.


Sub SaveMarketing()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Dim FileName As String<o:p></o:p>
FileName = Range("I3")<o:p></o:p>
MsgBox FileName<o:p></o:p>
ActiveWorkbook.SaveAs FileName:= _<o:p></o:p>
"\\Server\chromosomal labs\Immigration\RS_AMTC\" & FileName, FileFormat:= _<o:p></o:p>
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=True _<o:p></o:p>
, CreateBackup:=False<o:p></o:p>
<o:p></o:p>
End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try giving it a WriteResPassword and leaving out the ReadOnlyRecommended argument.

Note:
required reading now that we have Excel 2007/2010 alongside Excel 2003 in many work environments:
http://www.rondebruin.nl/saveas.htm
 
Upvote 0
check out the SetAttr statement (VB help)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SetAttr Statement


Sets attribute information for a file.

Syntax

SetAttr pathname, attributes

The SetAttr statement syntax has these named arguments:

Part Description
pathname Required. String expression that specifies a file name — may include directory or folder, and drive.
attributes Required. Constant or numeric expression, whose sum specifies file attributes.



Settings

The attributes argument settings are:

Constant Value Description
vbNormal 0 Normal (default).
vbReadOnly 1 Read-only.
vbHidden 2 Hidden.
vbSystem 4 System file. Not available on the Macintosh.
vbArchive 32 File has changed since last backup.
vbAlias 64 Specified file name is an alias. Available only on the Macintosh.



Note These constants are specified by Visual Basic for Applications. The names can be used anywhere in your code in place of the actual values.

Remarks

A run-time error occurs if you try to set the attributes of an open file.
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,348
Members
452,907
Latest member
Roland Deschain

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