What do mean by "I'm trying to write something that will save the workbook
in its initial state." What is the initial state? Otto
"kev_06" wrote in
message ...
Since most of the people that view this workbook may not enable their
macros at start, the workbook doesn't do anything. I've added a sheet,
Sheet 1, that explains this and tells them to enable macros. I want
this sheet to be the first one displayed whenever the workbook is open.
This is fine when macros are enabled, but it isn't when they are
disabled. So, I'm trying to write something that will save the workbook
in its initial state and then return to the sheet after the save has
been completed.
The code:
Public strname As String
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
strname = ThisWorkbook.ActiveSheet.Name
Cancel = True
Application.EnableEvents = False
Sheet4.Visible = xlSheetHidden
Sheet1.Visible = xlSheetVisible
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
wks.Protect
wks.EnableSelection = xlNoSelection
Next wks
ThisWorkbook.Save
ThisWorkbook.Saved = True
Application.EnableEvents = True
Sheet1.Select
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If strname = "" Then
Exit Sub
ElseIf Worksheets(strname).Name = "Sheet1" Then
Exit Sub
Else
Worksheets(strname).Select
strname = ""
End If
End Sub
--
kev_06
------------------------------------------------------------------------
kev_06's Profile:
http://www.excelforum.com/member.php...o&userid=35046
View this thread: http://www.excelforum.com/showthread...hreadid=550078