Returns the login context handle of the specified connected worksheet.
EssVGetHctxFromSheet(sheetName)
ByVal sheetName As VariantText name of worksheet to operate on. sheetName is of the form "[Book.xls]Sheet". If sheetName is Null or Empty, the active worksheet is used.
Returns 0 for failure. Failure may indicate that the worksheet is not logged in. Otherwise, the return value is the login context for the specified worksheet.
' Functions from Excel VBA
Declare Function EssVGetHctxFromSheet Lib "ESSEXCLN.XLL" (ByVal sheetName As Variant) As Long
Declare Function EssVConnect Lib "ESSEXCLN.XLL" (ByVal sheetName As Variant, ByVal UserName As Variant, ByVal password As Variant, ByVal server As Variant, ByVal application As Variant, ByVal database As Variant) As Long
' Functions from VB API
Declare Function EsbExport Lib "ESBAPIN.DLL" (ByVal hCtx As Long, ByVal AppName As String, ByVal DbName As String, ByVal FilePath As String, ByVal Level As Integer, ByVal isColumns As Integer) As Long
Declare Function EsbGetProcessState Lib "ESBAPIN.DLL" (ByVal hCtx As Long, ProcState As Esb_PROCSTATE_T) As Long
Dim hCtx As Long
Dim sts As Long
Dim AppName As String
Dim DbName As String
Dim PathName As String
Dim Level As Integer
Dim Columns As Integer
Sub CheckContext()
'Check hCtx, a non zero value indicates the sheet
'is connected. If it is zero, Connect.
If hCtx = 0 Then
hCtx = EssVGetHctxFromSheet("[SAMPVBA.XLS]")
If hCtx = 0 Then
X = EssVConnect("[SAMPVBA.XLS]", "RonC", "password", "magnolia", "Sample", "Basic")
hCtx = EssVGetHctxFromSheet("[SAMPVBA.XLS]")
If hCtx = 0 Then
MsgBox("Error connecting to sheet.")
GoTo Quit
End If
If X <> 0 Then
MsgBox("Connect Failed. Error: " + X)
End If
End If
End If
AppName = "Sample"
DbName = "Basic"
PathName = "c:\export.txt"
Level = Esb_DATA_INPUT
Columns = Esb_NO
' Export it
sts = EsbExport(hCtx, AppName, DbName, PathName, Level, Columns)
If sts <> 0 Then
MsgBox ("Export Failed. Error " + Str$(sts))
End If
' Check Process State until Done
sts = EsbGetProcessState(hCtx, ProcState)
Do While ProcState.State = Esb_STATE_INPROGRESS
sts = EsbGetProcessState(hCtx, ProcState)
Loop
If sts = 0 Then
Sheets("Sheet1").Select
MsgBox ("Export Completed.")
Else
MsgBox ("Export failed.")
End If
Quit:
End SubThese Essbase Visual Basic API functions should not be called with the context handle returned by EssVGetHctxFromSheet: EsbLogout, EsbSetActive, and EsbClearActive. The results are unpredictable and unsupported.
Do not call the Essbase Visual Basic API function EsbInit in the same VBA module as EssVGetHctxFromSheet. The results are unpredictable and unsupported.