Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Workbook_Open event not called when workbook forced to re-open in read-only mode.

Hi Guys

I have a spreadsheet with some logic that:

* does the old "macros must be enabled" trick by only leaving one
"instruction" sheet visible upon saving so that when its opened with
macros disabled the user can not access the actual data sheets - these
are revealed when the workbook is opened with macros enabled (ala
similar discussions on this group - I know this is not crack proof)

* on the Workbook_Open event re-opens the spreadsheet as read-only
if the Application.UserName is not in a defined list - the code looks
like this:

' re-open this workbook in read-only mode
Sub Reopen_Read_Only()
Application.EnableEvents = True
Application.DisplayAlerts = False ' supress message about file
already open as this is intended
' DEBUG MsgBox "EnableEvents: " & Application.EnableEvents
Workbooks.Open Filename:=ThisWorkbook.Path & "\" &
ThisWorkbook.Name, ReadOnly:=True
End Sub

The problem is that when Reopen_Read_Only is called the spreadsheet re-
opens nicely as read-only but Workbook_Open is *not* called as though
events are disabled. This is a problem, of course, due to my "macros
disabled" logic as described above. The weird thing is then when fully
opened events are enabled but Workbook_Open never gets called on the
re-open!!!

Does anyone have a clue for me why this would happen? Can I configure
a workbook to enable events when it opens? I dont think you can.

Cheers for any ideas.
Chrisso

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Workbook_Open event not called when workbook forced to re-open inread-only mode.

I think I'd drop the reopening as readonly and just use something like:

ThisWorkbook.ChangeFileAccess Mode:=xlReadOnly

ps.

ThisWorkbook.Path & "\" & ThisWorkbook.Name
is the same as:
ThisWorkbook.FullName

Chrisso wrote:

Hi Guys

I have a spreadsheet with some logic that:

* does the old "macros must be enabled" trick by only leaving one
"instruction" sheet visible upon saving so that when its opened with
macros disabled the user can not access the actual data sheets - these
are revealed when the workbook is opened with macros enabled (ala
similar discussions on this group - I know this is not crack proof)

* on the Workbook_Open event re-opens the spreadsheet as read-only
if the Application.UserName is not in a defined list - the code looks
like this:

' re-open this workbook in read-only mode
Sub Reopen_Read_Only()
Application.EnableEvents = True
Application.DisplayAlerts = False ' supress message about file
already open as this is intended
' DEBUG MsgBox "EnableEvents: " & Application.EnableEvents
Workbooks.Open Filename:=ThisWorkbook.Path & "\" &
ThisWorkbook.Name, ReadOnly:=True
End Sub

The problem is that when Reopen_Read_Only is called the spreadsheet re-
opens nicely as read-only but Workbook_Open is *not* called as though
events are disabled. This is a problem, of course, due to my "macros
disabled" logic as described above. The weird thing is then when fully
opened events are enabled but Workbook_Open never gets called on the
re-open!!!

Does anyone have a clue for me why this would happen? Can I configure
a workbook to enable events when it opens? I dont think you can.

Cheers for any ideas.
Chrisso


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Workbook_Open event not called when workbook forced to re-open in read-only mode.

Thanks Dave. That rocks - just the tonic.

Chrisso


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
workbook_open not being called when I open the excel file Hany Excel Programming 3 April 8th 06 01:34 PM
Private Sub Workbook_Open() event won't fire if workbook is hidden? Mike Weaver Excel Programming 2 February 15th 06 01:38 PM
Testing of a workbook is in read only mode GLT Excel Programming 1 January 24th 06 04:39 PM
Run Workbook_Open only if called Jarek[_14_] Excel Programming 0 September 18th 04 10:05 AM
Run Workbook_Open only if called Jarek[_13_] Excel Programming 1 September 17th 04 03:10 PM


All times are GMT +1. The time now is 04:20 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"