Handling Trappable Errors from OLE Servers
When programming with OLE objects, you can receive trappable errors from three sources:
- Visual Basic. The Visual Basic OLE trappable error codes range from 430-450. Most of these error deal with OLE Automation objects.
- The OLE .DLLs. These errors come across as user-defined error codes in the range 31000-32000. These are the error codes you usually see when dealing with linked and embedded objects.
- The OLE object's application. Each application has its own defined range of error codes it returns. Word error messages range from 1000-1600. Excel's error codes range from 1000-1006. These errors only occur when working with each application's objects through OLE Automation.
There are two programming strategies for trapping these errors, as follows:
- Polling using On Error Resume Next
- Error handlers using On Error Goto
Polling is essential when programming with OLE objects. Errors from OLE object's applications tend to be vague - Excel defines seven errors to cover about 1400 methods and properties. You usually need to know exactly what line of code failed to handle the situation effectively.