View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
John John is offline
external usenet poster
 
Posts: 2,069
Default opening a workbook as read only

this should do what you want. Place in standard module.

Sub OpenBook()
Dim myfile As String
Dim passwrd As String
Dim wb As Workbook

'change file path & name as required
myfile = "C:\myfolder\myfilename.xls"

'change password as required
passwrd = "mypassword"

If Day(Now) 9 And Day(Now) < 17 Then
'OPEN WORKBOOK AS READ ONLY
msg = MsgBox("You can only access this spreadsheet between" &
Chr(10) & _
"the 17th of the month and the 8th of the following
month", vbInformation, "Open Workbook")

Set wb = Workbooks.Open(myfile, ReadOnly:=True, Password:=passwrd)

Else
'OPEN WORKBOOK NORMALLY

Set wb = Workbooks.Open(myfile, ReadOnly:=False, Password:=passwrd)

End If

End Sub
--
jb


"Valeria" wrote:

Dear experts,
I have a workbook containing macros which I would like to open as read-only
on certain days.
E.g.:
If Day(Now) 9 And Day(Now) < 17 Then
'OPEN WORKBOOK AS READ ONLY
msgbox ("You can only access this spreadsheet between the 17th of the month
and the 8th of the following month")
Else
'OPEN WORKBOOK NORMALLY
End If

Is this possible? what would be the code for it? And would my macros still
work?

Thanks!
Kind regards

--
Valeria