Code not executing

I

iwrk4dedpr

I'm wondering if anybody has come accros a problem similar to this.


I have a workook which when it opens begins an automatic updat
process. When the process is complete the workbook is to close.
However, in the code in the close event it won't executet he code.
There are no errors the code just doesn't perform.

For example the one line of code is Me.Save. The workbook doe
nothing. Now if I insert a Cancel = True, then abort the code, an
then close the workbook manually when I step through the cod
everything works perfectly.


I use a OLE object and I'm wondering if that could be the cause.
However, I use the same object in other books without issue. Ha
anybody ever seen this problem and it's cause
 
F

Frank Kabel

Hi
you may show the code in your workbook_open event and in your
workbook_beforeclose event
 
I

iwrk4dedpr

As per request. Here are the Open and Close events for the workbook.

Private Sub Workbook_BeforeClose(Cancel As Boolean)

' Initialize all global variables
If Not gblnGlobalVariablesInit Then Cal
Initialize_Global_Variables

' Local Variables
Dim intWkbsOpen As Integer
Dim wkb As Workbook

' Step 1 : Only proceed if logged in user is the current workboo
owner
If gstrPCLoginUser <> UCase(Range("ad_wi_Owner").Offset(0, 2)
Then
Me.Saved = True
Cancel = True
Exit Sub
End If

' Step 2 : Update set file access status to ReadWrite
If Me.ReadOnly Then
Me.Saved = True
Call wkscmd_ToggleReadOnly
End If

' Step 3 : Save workbook
Me.Save

' Step 3 : Determine how to close
intWkbsOpen = Application.Workbooks.Count
For Each wkb In Application.Workbooks
If wkb.Name = "Personal.xls" Then intWkbsOpen = intWkbsOpen
1
Next wkb
If intWkbsOpen = 1 Then Application.Quit


End Sub


Private Sub Workbook_Open()

' Initialize all global variables
If Not gblnGlobalVariablesInit Then Cal
Initialize_Global_Variables

' Local Variables


' Step 1 : Always reset file access to ReadOnly on opening
If Not Me.ReadOnly Then
Me.Saved = True
Me.ChangeFileAccess Mode:=xlReadOnly
End If

' Step 2 : Always rehide all sheets
Call wkscmd_ToggleSheetVis(True)

' Step 3 : Initiate auto processing
Call PerformAutoContinue

End Sub


I'm not having any luck reducing the file size to less than the 1M
limit imposed on attachments. So if you need more code I can U2U wit
the actual workbook
 
B

Berend Botje

I have had a similar error. It had to do with my script opening a secon
workbook (and activating it), but I still referred to the firs
workbook (which contained the script) as the ActiveWorkbook.

I don't know if this is similar to the problem you are experiencing
but maybe it helps you...
 
Top