Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default opening a workbook as read only

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default opening a workbook as read only

Hi John,
thanks, however I am referring to the same workbook where the code is placed
who should open as read only or normally... it is not a separate one.

I guess I should put some code in the Workbook_Open procedure but I am not
sure how to tell my workbook to open itself as read only! (if it's possible
at all).
Thanks,
Kind regards
--
Valeria


"john" wrote:

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

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

Don't think that is possible once file has been opened but could be wrong!

My understanding is that by default, all files created and opened in
Microsoft Excel are read write files. This applies not only to Microsoft
Excel but almost all other applications. Also, a file cannot be created read
only just because if you create a read only file you can never edit it. But
you can make a file read only so that others don't tamper with it.

To make a Excel file read only (Microsoft Excel 2003),


Goto Tools -Options-Security (The Tools menu in the worksheet menu bar)

Check the READ-ONLY RECOMMENDED box.
This would make your file read only and when the file is opened, it would
prompt you with the message box whether you want the file to be opened in
read only mode or not. If you click YES, the file would open in read only
mode. If you click NO, the file would open in read write mode and you can
save your changes.

For Microsoft Excel 2000 and other previous versions

Goto File-Save As
Click the TOOLS button on the right corner and select GENERAL OPTIONS
Now check the READ-ONLY RECOMMENDED box.
This works well in Microsoft Excel 2003 also.

The above option, though making the file read only, gives the user the
option to edit it. So even if an user unknowingly presses the NO button ,
when prompted for read only opening, he may still be able to edit the file.
If you want to prevent this then,

Navigate to your file through Windows Explorer or the File Open Box and
select it.

RIGHT CLICK and select PROPERTIES
Check the READ ONLY box.
This always open the file read only and even if you already made your file
read only, by using the first option, this overrides it since this function
is part of the operating system rather than the application. To make the file
read write again, just uncheck the READ ONLY box.

This may not be what you were looking for but may give you another idea how
to resolve your requirement

Hope helpful

--
jb


"Valeria" wrote:

Hi John,
thanks, however I am referring to the same workbook where the code is placed
who should open as read only or normally... it is not a separate one.

I guess I should put some code in the Workbook_Open procedure but I am not
sure how to tell my workbook to open itself as read only! (if it's possible
at all).
Thanks,
Kind regards
--
Valeria


"john" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default opening a workbook as read only

Hi John
many thanks - I guess I was asking too much!!!!
Kind regards
--
Valeria


"john" wrote:

Don't think that is possible once file has been opened but could be wrong!

My understanding is that by default, all files created and opened in
Microsoft Excel are read write files. This applies not only to Microsoft
Excel but almost all other applications. Also, a file cannot be created read
only just because if you create a read only file you can never edit it. But
you can make a file read only so that others don't tamper with it.

To make a Excel file read only (Microsoft Excel 2003),


Goto Tools -Options-Security (The Tools menu in the worksheet menu bar)

Check the READ-ONLY RECOMMENDED box.
This would make your file read only and when the file is opened, it would
prompt you with the message box whether you want the file to be opened in
read only mode or not. If you click YES, the file would open in read only
mode. If you click NO, the file would open in read write mode and you can
save your changes.

For Microsoft Excel 2000 and other previous versions

Goto File-Save As
Click the TOOLS button on the right corner and select GENERAL OPTIONS
Now check the READ-ONLY RECOMMENDED box.
This works well in Microsoft Excel 2003 also.

The above option, though making the file read only, gives the user the
option to edit it. So even if an user unknowingly presses the NO button ,
when prompted for read only opening, he may still be able to edit the file.
If you want to prevent this then,

Navigate to your file through Windows Explorer or the File Open Box and
select it.

RIGHT CLICK and select PROPERTIES
Check the READ ONLY box.
This always open the file read only and even if you already made your file
read only, by using the first option, this overrides it since this function
is part of the operating system rather than the application. To make the file
read write again, just uncheck the READ ONLY box.

This may not be what you were looking for but may give you another idea how
to resolve your requirement

Hope helpful

--
jb


"Valeria" wrote:

Hi John,
thanks, however I am referring to the same workbook where the code is placed
who should open as read only or normally... it is not a separate one.

I guess I should put some code in the Workbook_Open procedure but I am not
sure how to tell my workbook to open itself as read only! (if it's possible
at all).
Thanks,
Kind regards
--
Valeria


"john" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening Workbook as Read Only and using ".Activate" John Brenner Excel Programming 2 January 13th 09 05:26 PM
Opening workbook automatically as Read-0nly excelnut1954 Excel Programming 5 May 3rd 06 06:43 PM
opening workbook as read-only or write-enabled archiboy Excel Programming 1 January 31st 06 01:11 PM
opening workbook as read-only Mariusz Excel Programming 2 May 25th 04 08:53 AM
Opening Excel Workbook from Word using VBA - Always Read Only Alan Excel Programming 0 November 5th 03 02:55 AM


All times are GMT +1. The time now is 05:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"