Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 234
Default Force Macro Enable

Below is code taken from Daniel Klann's site.
http://www.danielklann.com/excel/for...be_enabled.htm

The idea is the sheets are hidden when you load the workbook and are unhidden (only) by the workbook_open event, so macros must be enabled to use the workbook. The BeforeClose event hides the sheets, but in order to work, forces the user to save. I've tried incorporating the beforesave event to allow the user the option of not saving, but even when I disable events, I get asked twice whether I want to save or not.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
HideSheets
End Sub

Private Sub Workbook_Open()
UnhideSheets
End Sub

Private Sub HideSheets()
Dim sht As Object
Application.ScreenUpdating = False
ThisWorkbook.Sheets("Macros Disabled").Visible = xlSheetVisible 'This sheet contains a message to the user.
For Each sht In ThisWorkbook.Sheets
If sht.Name < "Macros Disabled" Then sht.Visible = xlSheetVeryHidden
Next sht
Application.ScreenUpdating = True
ThisWorkbook.Save
End Sub

Private Sub UnhideSheets()
Dim sht As Object
Application.ScreenUpdating = False
For Each sht In ThisWorkbook.Sheets
sht.Visible = xlSheetVisible
Next sht
ThisWorkbook.Sheets("Macros Disabled").Visible = xlSheetVeryHidden
Application.ScreenUpdating = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Force Macro Enable

If you don't save, then the sheets won't be hidden when the workbook is next
open which defeats the whole approach. So using it, while a waste of time
before, becomes an even more complete waste of time now.

--
Regards,
Tom Ogilvy

"Rob" wrote in message
...
Below is code taken from Daniel Klann's site.
http://www.danielklann.com/excel/for...be_enabled.htm

The idea is the sheets are hidden when you load the workbook and are

unhidden (only) by the workbook_open event, so macros must be enabled to use
the workbook. The BeforeClose event hides the sheets, but in order to work,
forces the user to save. I've tried incorporating the beforesave event to
allow the user the option of not saving, but even when I disable events, I
get asked twice whether I want to save or not.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
HideSheets
End Sub

Private Sub Workbook_Open()
UnhideSheets
End Sub

Private Sub HideSheets()
Dim sht As Object
Application.ScreenUpdating = False
ThisWorkbook.Sheets("Macros Disabled").Visible = xlSheetVisible 'This

sheet contains a message to the user.
For Each sht In ThisWorkbook.Sheets
If sht.Name < "Macros Disabled" Then sht.Visible =

xlSheetVeryHidden
Next sht
Application.ScreenUpdating = True
ThisWorkbook.Save
End Sub

Private Sub UnhideSheets()
Dim sht As Object
Application.ScreenUpdating = False
For Each sht In ThisWorkbook.Sheets
sht.Visible = xlSheetVisible
Next sht
ThisWorkbook.Sheets("Macros Disabled").Visible = xlSheetVeryHidden
Application.ScreenUpdating = True
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 234
Default Force Macro Enable

Thanks for your response Tom. If macros are preventing user 'breaking' the workbook then it's not a waste of time to force the user to enable them.
The fact that if you don't save then sheets won't be hidden when the workbook is next open was precisely my point. I'd like to remove the line where the book is saved from the hidesheets sub, and then use the beforesave event similarly to below. By doing so, any SAVED version of the workbook will have the sheets hidden. The problem I'm having is that the Save changes dialog appears twice, and I can't see why.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
cancel=true
application.enableevents=false
hidesheets
thisworkbook.save
unhidesheets
application.enableevents=true
end sub


----- Tom Ogilvy wrote: -----

If you don't save, then the sheets won't be hidden when the workbook is next
open which defeats the whole approach. So using it, while a waste of time
before, becomes an even more complete waste of time now.

--
Regards,
Tom Ogilvy

"Rob" wrote in message
...
Below is code taken from Daniel Klann's site.
http://www.danielklann.com/excel/for...be_enabled.htm
The idea is the sheets are hidden when you load the workbook and are

unhidden (only) by the workbook_open event, so macros must be enabled to use
the workbook. The BeforeClose event hides the sheets, but in order to work,
forces the user to save. I've tried incorporating the beforesave event to
allow the user the option of not saving, but even when I disable events, I
get asked twice whether I want to save or not.
Private Sub Workbook_BeforeClose(Cancel As Boolean)

HideSheets
End Sub
Private Sub Workbook_Open()

UnhideSheets
End Sub
Private Sub HideSheets()

Dim sht As Object
Application.ScreenUpdating = False
ThisWorkbook.Sheets("Macros Disabled").Visible = xlSheetVisible 'This

sheet contains a message to the user.
For Each sht In ThisWorkbook.Sheets
If sht.Name < "Macros Disabled" Then sht.Visible =

xlSheetVeryHidden
Next sht
Application.ScreenUpdating = True
ThisWorkbook.Save
End Sub
Private Sub UnhideSheets()

Dim sht As Object
Application.ScreenUpdating = False
For Each sht In ThisWorkbook.Sheets
sht.Visible = xlSheetVisible
Next sht
ThisWorkbook.Sheets("Macros Disabled").Visible = xlSheetVeryHidden
Application.ScreenUpdating = True
End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Force Macro Enable

I only get two prompts if I choose to save in response to the first to the
first prompt - same for you?

Close the workbook
BeforeClose
HideSheets
Executes a Save
Fires BeforeSave
Events off,
Save Canceled
Hide Sheets
Executes a Save
File is Saved
Back to BeforeSave
File is Saved
Unhide Sheets
Events back on
Back to BeforeClose
BeforeClose Ends
Workbook is Dirty prompt for Save, User clicks yes
BeforeSave
Events Off
Save Cancelled
Hide Sheets
Executes a Save
File is Saved
Back to BeforeSave
File is Saved
UnHide Sheets
Events Back on
Excel must recheck if the workbook has changed and issue another prompt.
If I answer no, 4 saves later and I am done.

--
Regards,
Tom Ogilvy

"Rob" wrote in message
...
Thanks for your response Tom. If macros are preventing user 'breaking'

the workbook then it's not a waste of time to force the user to enable them.
The fact that if you don't save then sheets won't be hidden when the

workbook is next open was precisely my point. I'd like to remove the line
where the book is saved from the hidesheets sub, and then use the beforesave
event similarly to below. By doing so, any SAVED version of the workbook
will have the sheets hidden. The problem I'm having is that the Save
changes dialog appears twice, and I can't see why.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As

Boolean)
cancel=true
application.enableevents=false
hidesheets
thisworkbook.save
unhidesheets
application.enableevents=true
end sub


----- Tom Ogilvy wrote: -----

If you don't save, then the sheets won't be hidden when the workbook

is next
open which defeats the whole approach. So using it, while a waste of

time
before, becomes an even more complete waste of time now.

--
Regards,
Tom Ogilvy

"Rob" wrote in message
...
Below is code taken from Daniel Klann's site.
http://www.danielklann.com/excel/for...be_enabled.htm
The idea is the sheets are hidden when you load the workbook and

are
unhidden (only) by the workbook_open event, so macros must be enabled

to use
the workbook. The BeforeClose event hides the sheets, but in order

to work,
forces the user to save. I've tried incorporating the beforesave

event to
allow the user the option of not saving, but even when I disable

events, I
get asked twice whether I want to save or not.
Private Sub Workbook_BeforeClose(Cancel As Boolean)

HideSheets
End Sub
Private Sub Workbook_Open()

UnhideSheets
End Sub
Private Sub HideSheets()

Dim sht As Object
Application.ScreenUpdating = False
ThisWorkbook.Sheets("Macros Disabled").Visible = xlSheetVisible

'This
sheet contains a message to the user.
For Each sht In ThisWorkbook.Sheets
If sht.Name < "Macros Disabled" Then sht.Visible =

xlSheetVeryHidden
Next sht
Application.ScreenUpdating = True
ThisWorkbook.Save
End Sub
Private Sub UnhideSheets()

Dim sht As Object
Application.ScreenUpdating = False
For Each sht In ThisWorkbook.Sheets
sht.Visible = xlSheetVisible
Next sht
ThisWorkbook.Sheets("Macros Disabled").Visible =

xlSheetVeryHidden
Application.ScreenUpdating = True
End Sub






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
force users to enable macro so sheet cannot be printed Zambian Excel Discussion (Misc queries) 3 December 10th 08 07:36 PM
How can force enable macros to be able to open my workbook? kcdonaldson Excel Discussion (Misc queries) 3 December 5th 05 06:16 PM
Force Enable Macros Jake Marx[_2_] Excel Programming 1 October 24th 03 01:24 AM
Force Enable Macros Alan Excel Programming 0 September 24th 03 08:17 PM
Force Enable Macros Ed[_9_] Excel Programming 0 September 24th 03 07:59 PM


All times are GMT +1. The time now is 11:35 PM.

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

About Us

"It's about Microsoft Excel"