VB and VBA Users Source Code: Returning helpful information from failed CreateObject
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Returning helpful information from failed CreateObject
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Monday, June 14, 2004
Hits:
1235
Category:
Office
Article:
Below is a useful function for obtaining error information about failed CreateObject calls... 'Purpose : Wrapped function around CreateObject which returns a helpful error message. ' i.e. not the useless ActiveX can't create component error. 'Inputs : sClass The class or progID of the object to create. ' sServer The server name to create the object on (defaults to local machine). 'Outputs : N/A 'Author : Andrew Baker 'Date : 03/03/2003 'Example : 'Revisions : Function CreateObject2(sClass As String, Optional sServer As String) As Object On Error GoTo ErrFailed If Len(sServer) = 0 Then Set CreateObject2 = CreateObject(sClass) Else Set CreateObject2 = CreateObject(sClass, sServer) End If Exit Function ErrFailed: Msgbox "Error failed to create ActiveX component... " & _ vbNewLine & "Component Name: " & IIf(Len(sServer), sServer & ".", "") & sClass & _ vbNewLine & "Error: " & Err.Description, vbCritical End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder