Don, Bob, thanks for replying. Here is (part of) my code (apologies fo
some names, but I use some Dutch in names, to avoid confusing wit
keywords):
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim intOpslaan As Integer
On Error GoTo ErrorHandler
StapAantal = 17
Call ProgrammaBegin
Call CopyrightCheck
Call WerkboekBerekenen
Call WerkboekStoppen
ErrorHandler:
If Err Then Call FoutAfhandeling("Auto_Close")
On Error GoTo Einde
Call WerkBalkenTerugzetten
Call ProgrammaEinde
Call CommandBarButton_Click
If ThisWorkbook.ReadOnly Then
ThisWorkbook.Saved = True
End If
If ThisWorkbook.Saved = False Then
intOpslaan = MsgBox("De wijzigingen in " & ThisWorkbook.FullName
vbCrLf & _
"zijn nog niet opgeslagen." & vbCrLf & vbCrLf & _
"Wilt u alsnog opslaan? ", vbYesNo + vbInformation
vbMsgBoxSetForeground, ThisWorkbook.Name)
If intOpslaan = vbYes Then Call mnuOpslaan
End If
ThisWorkbook.Saved = True
End
Einde:
If Err Then Call FoutAfhandeling("Auto_Close")
Erase aRow()
Erase aColumn()
Erase aRange()
Set OldCell = Nothing
Set HuidigBlad = Nothing
Set HuidigeCel = Nothing
Set PB = Nothing
Set colCBS = Nothing
End Sub
This is in the "ThisWorkbook" module: ProgrammaBegin contains setting
and is in a separate module:
Sub ProgrammaBegin()
Dim Teller As Integer
Call mnuActiveren
ReDim Preserve aRow(ThisWorkbook.Worksheets.Count) As Long
ReDim Preserve aColumn(ThisWorkbook.Worksheets.Count) As Integer
ReDim Preserve aRange(ThisWorkbook.Worksheets.Count) As String
lngCalcMode = Application.Calculation
With Application
.OnKey "%{F11}", ""
.OnKey "%{F8}", ""
.OnKey "^{BREAK}", ""
.EnableCancelKey = xlDisabled
.CutCopyMode = False
.EnableEvents = False
.DisplayAlerts = False
.Interactive = False
.DisplayCommentIndicator = xlNoIndicator
.Calculation = xlCalculationManual
.IgnoreRemoteRequests = True
.WindowState = xlMaximized
.ScreenUpdating = False
End With
Set PB = New clsProgBar
PB.Title = ThisWorkbook.Name
PB.Caption1 = "Even geduld alstublieft"
PB.Caption2 = "gegevens worden bijgewerkt"
PB.Show
StapNummer = 0
Select Case ActiveSheet.Name
Case strMacroSecurity
Sheets(strRitten).Activate
Case strTransport
Sheets(strRitten).Activate
Case strDatabaseRoutes
Sheets(strRitten).Activate
End Select
Set HuidigBlad = ActiveSheet
Set HuidigeCel = ActiveCell
For Teller = 1 To ThisWorkbook.Worksheets.Count
Worksheets(Teller).Activate
Call VensterPositieBewaren(Teller) ' run this before makin
changes
Next Teller
If Worksheets(HuidigBlad.Name).Visible = True Then
Application.GoT
Reference:=Sheets(HuidigBlad.Name).Range(HuidigeCe l.Address)
End If
Call StatusBalkUpdaten
End Sub
The code activated by the button is:
Sub mnuAfsluiten()
ThisWorkbook.Close ' Activeworkbook.close gives the same problems
End Sub
When the code in "Workbook_Beforeclose" is in the "Auto_close" macro
everything works fine. Thanks for trying to help me!
Pau
--
phcvergouw
-----------------------------------------------------------------------
phcvergouwe's Profile:
http://www.excelforum.com/member.php...fo&userid=3465
View this thread:
http://www.excelforum.com/showthread.php?threadid=54425