我有一个Excel文件(Get_Hyperion_Data.xlsm),其中包含多个工作表,每个工作表都包含一个hyperion报告,其中使用“ HsGetValue()”函数来检索数据。
我创建了一个宏,该宏允许我指定两个变量(“年份”和“方案”),并在更新所述变量后刷新每个工作表。 如果我打开此excel文件,指定变量并启动宏,则整个报表将按预期刷新,而没有任何问题。我已经为下面的宏提供了代码
我想在自动化方面更进一步,并创建一个VB脚本,该脚本将打开Get_Hyperion_Data.xlsm,指定变量并调用刷新宏。
但是,当我尝试通过VB脚本触发宏时,会发生一些奇怪的事情。 我收到错误消息
“ Essbase错误:成员[方案]不合适”。
考虑到我自己打开Excel并运行宏时没有出现任何错误,这很奇怪。只有当我尝试通过VB Script进行所有操作时,才会收到此消息。
这是我正在运行的简单脚本:
' Refresh_Hyperion_Reports.vbs
' Open Hyperion report and launch macro to refresh values
' ------------------------------------------------'
Option Explicit
Dim xlApp
Dim xlBook
Dim colArgs
Dim argLocation, argYear, argScenario, argUser, argPassword, argConnection
Set colArgs = WScript.Arguments.Named
argLocation = Cstr(colArgs.Item("location"))
argYear = Cstr(colArgs.Item("year"))
argScenario = Cstr(colArgs.Item("scenario"))
argUser = Cstr(colArgs.Item("user"))
argConnection = Cstr(colArgs.Item("connection"))
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.DisplayAlerts = True
Set xlBook = xlApp.Workbooks.Open(argLocation, 0, False)
xlApp.Run "call_RefreshReports", argYear, argScenario, argUser, argPassword, argConnection
xlBook.Save
xlApp.ActiveWorkbook.Close
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
关于VB Script与Hyperion的交互,我似乎没有找到任何具体建议,所以我问你们中是否有人遇到过此问题? 下面是VBA宏:
```
Sub RefreshReports(valYear, valScenario, valUser, valPassword, valConnection)
Dim sh_array As Variant
Dim refresh_range As Range
'Disable screen updating, disable automatic calculations
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Application.AutoCorrect.AutoFillFormulasInLists = False
'Error handling
On Error GoTo EndFunction
'Specify data/report sheets
sh_array = Array("Validation", "Total Operating Expenses", "Total Revenue", "Stats Accounts", "Net Income After Taxes")
'assign and convert function parameters
shParameters.Range("rangeYear").Value = CStr(valYear)
shParameters.Range("rangeScenario").Value = CStr(valScenario)
ThisWorkbook.RefreshAll
Application.Calculate
'Loop through each report sheet,connect to hyperion with parametred username and password and refresh the sheet
For i = LBound(sh_array) To UBound(sh_array)
Debug.Print "Refreshing Sheet: " & ThisWorkbook.Sheets(sh_array(i)).Name
ThisWorkbook.Sheets(sh_array(i)).Activate
x = HypConnect(ThisWorkbook.Sheets(sh_array(i)).Name, valUser, valPassword, valConnection)
Call HypMenuVRefresh
Application.Wait Time + TimeSerial(0, 0, 5)
Application.CalculateFullRebuild
DoEvents
Next i
HypDisconnectAll
shParameters.Activate
RefreshReports = True
Application.AutoCorrect.AutoFillFormulasInLists = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub