LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Propogating errors after closing Workbook.

I am having a problem with propogating errors through a
series of error handlers in Excel VBA. Errors are
propogated as expected in most cases, but if I close an
Excel Workbook prior to the error first being raised, then
the error does not propogate normally.

To demonstrate this problem, I have created a new Excel
workbook that contains two classes (Topology and System)
and one module. The module contains only the
procedure "Testit" that shows the problem.

Public Sub Testit()
Dim topTest As New Topology
topTest.TopoMethod
Exit Sub
End Sub

TopoMethod is the only method in the Topology class:

Public Sub TopoMethod()

Dim sysTest As New System
On Error GoTo ErrorHandler
sysTest.SysMethod
Exit Sub

ErrorHandler:
Debug.Print "TopoMethod", Err.Number,
Err.Source, _
vbCrLf & " " &
Err.Description, vbCrLf
Exit Sub
End Sub

SysMethod is the only method in the System class:

Public Sub SysMethod()

Dim wbkSystemDB As Workbook
On Error GoTo ErrorHandler
Set wbkSystemDB = Workbooks.Open
(Filename:=ThisWorkbook.Path & "\" & "TestFile.xls")
'~~ wbkSystemDB.Close SaveChanges:=False '
This is the line that causes the problem!
Err.Raise Number:=vbObjectError + 10000, _
Source:="System", _
Description:="This is a test error
message from SysMethod."
Exit Sub

ErrorHandler:
Debug.Print "SysMethod", Err.Number,
Err.Source, vbCrLf & " " & Err.Description, vbCrLf
Err.Raise Err.Number, Err.Source,
Err.Description

End Sub

"TestFile.xls" can be any Excel Workbook. (In this case
it is a dummy Excel Workbook containing only an empty
sheet.) When the statement that closes the workbook is
commented out as shown, then running Testit results in the
following output in the immediate window:

SysMethod -2147211504 SystemSrc
This is a test error message from
SysMethod.

TopoMethod -2147211504 SystemSrc
This is a test error message from
SysMethod.

This output represents what I expect and want. However,
if the statement that closes the Excel Workbook is not
commented out, then running Testit results in this output
in the immediate window:

SysMethod -2147211504 SystemSrc
This is a test error message from
SysMethod.

TopoMethod -2147211504 VBAProject
Method 'SysMethod' of object 'System'
failed

The error Number property is propogated correctly in both
cases. But in the latter case the Source and Description
properties have been lost/replaced.

I have tried some simple solutions, such as adding
DoEvents after the Workbook close, but have had no success
in finding a workaround for this problem. Any ideas or
suggestions would be greatly appreciated. (I am running
Excel 2000 (9.0.4402 SR-1) on a Windows 2000 (5.00.2195
Service Pack 4) system.)

Thanks for any suggestions.

Cheers,
Randy

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing a workbook N1KO Excel Discussion (Misc queries) 0 February 12th 09 03:51 PM
Propogating data Bunky Excel Discussion (Misc queries) 2 August 6th 07 02:18 PM
Self propogating list Dos Equis Excel Worksheet Functions 0 March 14th 07 04:35 PM
Help with closing down a workbook?? Don Excel Worksheet Functions 1 May 9th 05 04:05 AM
closing workbook Sam Dickins Excel Programming 1 November 27th 03 03:43 PM


All times are GMT +1. The time now is 01:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"