There's not a whole lot you can do in the zero document state. My solution is to use structured error handling to catch and handle the errors. That alone won't get you cprofile in all situations, but I included it because I don't know what else you are doing in zero doc state. To get the current profile, don't use the Get variable method, which belongs to the Document object, use the AcadApplication.Preferences.Profile object.
In a regular module that instantiates the class module:
Dim x As New clsEvents 'events stored here
Public Sub AutoRun()
On Error GoTo Err_Control
Set x.app = AcadApplication
If AcadApplication.Documents.Count >= 0 Then Set x.Doc = ThisDrawing
Exit_Here:
Exit Sub
Err_Control:
Select Case Err.Number
'Add your Case selections here
'Case Is = 1000
'Handle error
'Err.Clear
'Resume Exit_Here
Case Else
MsgBox Err.Number & ", " & Err.Description, , "AutoRun"
Err.Clear
Resume Exit_Here
End Select
End Sub
The class module:
Option Explicit
Public WithEvents app As AcadApplication
Public WithEvents Doc As AcadDocument
Private Sub app_AppActivate()
On Error GoTo Err_Control
DisplayProfile:
'MsgBox Doc.GetVariable("cprofile")
MsgBox app.Preferences.Profiles.ActiveProfile
Exit_Here:
Exit Sub
Err_Control:
Select Case Err.Number
Case 91
'ThisDrawing object not available
Err.Clear
Resume Exit_Here
Case -2145320900
'Failed to get the Document object
Err.Clear
Resume Exit_Here
Case Else
MsgBox Err.Number & ", " & Err.Description, , "App.Activate"
Resume Exit_Here
End Select
End Sub
Ed
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to
post your code.