EssVGetHctxFromSheet

Description

Returns the login context handle of the specified connected worksheet.

Syntax

EssVGetHctxFromSheet(sheetName)
ByVal sheetName As Variant

Parameters

sheetName

Text 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.

Return Value

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.

Example

' 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 Sub

Notes: