Home |
Search |
Today's Posts |
#3
![]()
Posted to microsoft.public.excel.setup
|
|||
|
|||
![]()
This code worked for me. You need to put it all in the ThosWorkbook code
module. Private Sub Workbook_Open() With Application 'disable the ESC key .EnableCancelKey = xlDisabled .ScreenUpdating = False Call UnhideSheets .ScreenUpdating = True 're-enable ESC key .EnableCancelKey = xlInterrupt End With End Sub ' Private Sub UnhideSheets() ' Dim Sheet As Object ' For Each Sheet In Sheets If Not Sheet.Name = "Prompt" Then Sheet.Visible = xlSheetVisible End If Next ' Sheets("Prompt").Visible = xlSheetVeryHidden ' Set Sheet = Nothing ActiveWorkbook.Saved = True End Sub Private Sub Workbook_BeforeClose(Cancel As Boolean) With Application .EnableCancelKey = xlDisabled .ScreenUpdating = False Call HideSheets .ScreenUpdating = True .EnableCancelKey = xlInterrupt End With End Sub Private Sub HideSheets() ' Dim Sheet As Object '< Includes worksheets and chartsheets ' With Sheets("Prompt") ' 'the hiding of the sheets constitutes a 'change that generates an automatic "Save?" _ 'prompt, so IF the book has already been 'saved prior to this point, the next line and the Lines 'relating to .[A100] below bypass the "Save?" dialog... If ThisWorkbook.Saved = True Then .[A100] = "Saved" ' .Visible = xlSheetVisible ' For Each Sheet In Sheets If Not Sheet.Name = "Prompt" Then Sheet.Visible = xlSheetVeryHidden End If Next ' If .[A100] = "Saved" Then [A100].ClearContents ThisWorkbook.Save End If ' Set Sheet = Nothing End With ' End Sub Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) ' Cancel = True ' MsgBox "You cannot save this!" End Sub -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "nobbyknownowt" wrote in message ... Is there any specific order that VBA should be put? I have a workbook which I want users not to be able to save. I have code to hide the sheets and leave a prompt sheet to make users enable macros and i also have code to not allow saves. They both work individually but when i put them together however the hide sheet code fails. Have put the code below Could someone set me on the correct road please? Thanks Nobby Option Explicit Private Sub Workbook_Open() With Application 'disable the ESC key EnableCancelKey = xlDisabled ScreenUpdating = False Call UnhideSheets ScreenUpdating = True 're-enable ESC key EnableCancelKey = xlInterrupt End With End Sub ' Private Sub UnhideSheets() ' Dim Sheet As Object ' For Each Sheet In Sheets If Not Sheet.Name = "Prompt" Then Sheet.Visible = xlSheetVisible End If Next ' Sheets("Prompt").Visible = xlSheetVeryHidden ' Set Sheet = Nothing ActiveWorkbook.Saved = True End Sub Private Sub Workbook_BeforeClose(Cancel As Boolean) With Application EnableCancelKey = xlDisabled ScreenUpdating = False Call HideSheets ScreenUpdating = True EnableCancelKey = xlInterrupt End With End Sub Private Sub HideSheets() ' Dim Sheet As Object '< Includes worksheets and chartsheets ' With Sheets("Prompt") ' 'the hiding of the sheets constitutes a change that generates 'an automatic "Save?" prompt, so IF the book has already 'been saved prior to this point, the next line and the lines 'relating to .[A100] below bypass the "Save?" dialog... If ThisWorkbook.Saved = True Then .[A100] = "Saved" ' Visible = xlSheetVisible ' For Each Sheet In Sheets If Not Sheet.Name = "Prompt" Then Sheet.Visible = xlSheetVeryHidden End If Next ' If .[A100] = "Saved" Then [A100].ClearContents ThisWorkbook.Save End If ' Set Sheet = Nothing End With ' End Sub Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Cancel = True MsgBox "You cannot save this!" End Sub -- nobbyknownowt |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Series order conflicts with line order | Charts and Charting in Excel | |||
tab order | Excel Discussion (Misc queries) | |||
purchase order counter in excel purchase order template | Excel Worksheet Functions | |||
I want a purchase order that includes page number (if to be order. | New Users to Excel | |||
Daily Macro to Download Data, Order and paste in order | Excel Worksheet Functions |