多个 Oracle Smartview 刷新在循环中不工作(当我单步执行代码时工作)

Multiple Oracle Smartview Refresh Not Working in a Loop (Works When I Step Through Code)

我有以下代码,当我逐行执行它时(或者甚至当我只执行 1 或 2 次循环迭代然后触发其余部分时),它就像一个魅力一样工作。当我从一个按钮 运行 它时,代码不起作用,因为 Hyperion Retrieve 永远不会为我更改的部门的每次迭代更新。部门本身得到正确更改(从 Excel 和生成的 PDF 文件中可以看出)。

因此,简而言之,代码运行时没有发现或捕获错误,但结果是一组具有相同数据的 PDF,尽管按下按钮 运行 时标记为不同的部门。

我在网上搜索了很多,尝试使用 DoEventsApplication.Wait 都没有成功。 运行按下按钮时,有谁知道如何确保每次循环迭代都会刷新?

Option Explicit

Declare Function HypMenuVRefresh Lib "HsAddin.dll" () As Long

Sub CreateAllPDFS()

'... setup code to declare variables and loop range ...


'loop through departments
Dim cel As Range
For Each cel In rngLoop 'rngLoop declared and set in setup code

    'set department on drivers tab
    wsDrivers.Range("B4").Value = "'" & cel.Value

    '*** --> tried to wait before the loop (just shot in the dark type thing)
    'Application.Wait (Now + TimeValue("00:00:02")) 'pauses for 10 seconds, adjust as needed

    'refresh hyperion
    Dim lngReturn As Long
    lngReturn = HypMenuVRefresh()

    ' *** --> tried Do Events
    'DoEvents
    '*** --> tried to wait after the loop
    'Application.Wait (Now + TimeValue("00:00:02")) 'pauses for 10 seconds, adjust as needed

        'quick error check
        If lngReturn <> 0 Then
            MsgBox "Could Not Refresh!"
            Exit Sub
        End If

    'save as pdf
    wsPL.ExportAsFixedFormat xlTypePDF, cel.Offset(, 1) & "\" & cel.Offset(, 2) & ".pdf", , , , , , False

Next

End Sub

我们参考 HypMenuVReresh 的联机文档,其中指出

HypMenuVRefresh() retrieves data into the active sheet, and places the data at the beginning of the active worksheet.

来源:https://docs.oracle.com/cd/E12032_01/doc/epm.921/html_hsv_user/hsv_help-13-63.htm#528899

因此,通过在执行 HypMenuVReresh.

之前激活目标工作sheet(即本例中的 wsPL.Activate)找到解决方案

因此,一般来说,总是在 HypMenuVRefresh 之前激活目标作品sheet 是个好习惯,因为 HypMenuVRefresh 如果刷新作品[=] 不会抛出错误27=] 未连接到 Hyperion 多维数据集。此外,可以声明 HypConnected() 以在刷新之前检查 sheet 是否连接到 Hyperion 多维数据集(即 Hyperion 可刷新)。

HypConnected() returns a true value if the sheet is connected to an provider and returns a false value if the sheet is not connected.