从 Visual Basic for Applications (VBA) 在 Exact Online 上执行 Invantive SQL

Execute Invantive SQL on Exact Online from Visual Basic for Applications (VBA)

我想 运行 在 Exact Online 数据源上 Excel 上 VBA 代码中的一些 Invantive SQL 语句。

我可以使用像这样的 UDF 函数调用:

I_SQL_SELECT_SCALAR("select fullname from me")

在 Excel sheet 中。

如何从 VBA 中检索全名?

首先,您必须从 Visual Basic 编辑器 -> 工具菜单 -> 引用中引用函数:

然后使用如下代码检索标量值:

Option Explicit

Sub RunSql()
On Error GoTo Catch
Dim result As Variant
'
' Get full name of current user.
'
If Not I_INTEGRATION_ACTIVE() Then
MsgBox "VBA integration not available. Please use the Tools menu to activate it."
End If

result = InvantiveControlUDFs.I_SQL_SELECT_SCALAR("fullname", "Me")
MsgBox ("Result is '" & result & "'.")
'
' Retrieve scalar value: =I_SQL_SELECT_SCALAR(fieldName;tableName;whereClause;orderByClause;postFix;valueNoValue;valueTooManyValues;process)
' Retrieve table: =I_SQL_SELECT_TABLE(sqlStatement;errorOnMoreRows;errorOnMoreColumns;addHeaderRow;process)
' Normally disabled: =I_SQL_SCALAR(process;sql)
'

Finally:
    Exit Sub
Catch:
    HandleError "RunSql"
End Sub

或检索结果集(通常用于矩阵公式):

Option Explicit

Sub RunSqlTable()
On Error GoTo Catch
Dim result() As Variant
'
' Get list of GLAccounts.
'
If Not I_INTEGRATION_ACTIVE() Then
MsgBox "VBA integration not available. Please use the Tools menu to activate it."
End If

result = InvantiveControlUDFs.I_SQL_SELECT_TABLE("select * from exactonlinerest..glaccounts")
Finally:
    Exit Sub
Catch:
    HandleError "RunSqlTable"
End Sub

I_SQL_SELECT_TABLE 的使用仅适用于 2017 年 10 月及以后的版本。