View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
AP[_3_] AP[_3_] is offline
external usenet poster
 
Posts: 33
Default Workbook_BeforeSave

I have a "Workbook_BeforeSave" subroutine (below) that works perfectly
in most PC's, but in my workplace, it only works selectively (only
small bits of the code within the subroutine work). The only bit that
triggers is the "MsgBox" line - everything else is ignored.

Could this be a security setting in my workplace PC's ? (since the
macro works fine on other PC's)

Thanks for your help.

---


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

Application.EnableCancelKey = xlDisabled

'Move cursor to default position
Application.ScreenUpdating = False
Sheets("Data").Select
admin_change = True
Cells(1, 100).Select
admin_change = False
ActiveWindow.ScrollRow = 1: ActiveWindow.ScrollColumn = 1
Display_all 'A subroutine that unhides any hidden cells

'Ensure all fields in "Input" sheet have been duly populated
r = 4
While Sheets("Data").Cells(r, 11).Value < ""
If
Application.WorksheetFunction.CountBlank(Sheets("D ata").Range("B" & r
& ":F" & r)) 0 Then
Cancel = True
Application.ScreenUpdating = True
admin_change = True
Sheets("Data").Range(Cells(r, 1), Cells(r, 11)).Select
'Sheets("Input").Cells(r, 1).EntireRow.Select
admin_change = False
MsgBox "The highlighted record is incomplete." & Chr(13) &
Chr(13) & "Please complete the record thoroughly before saving this
file.", 16, "MIS Incomplete Record"
Exit Sub
End If
r = r + 1
Wend

'Hide sheets
ActiveWorkbook.Unprotect Password:=pro
Sheets("Notice").Visible = True
Sheets("Data").Visible = False
Sheets("Print_buffer").Visible = False
Sheets("Email_buffer").Visible = False
Sheets("Buffer").Visible = False
Sheets("Options").Visible = False
Sheets("Notice").Select
ActiveWorkbook.Protect Password:=pro, Structu=True,
Windows:=False
Application.ScreenUpdating = True

'Restore view
DoEvents
Application.OnTime Now + TimeValue("00:00:01"),
"Restore_view_after_saving"

End Sub