运行时错误1004 - 找不到BloombergUI

问题描述 投票:0回答:2

我正在运行一个批处理文件,该文件执行一个VBScript,它在Bloomberg终端上的Excel工作表中运行一个宏。

excel表在单元格中包含许多BDP公式。一切都很好。最初,我有一个问题从Bloomberg更新数据并运行宏,但这是通过使用bloombergui.xla.RefreshAllStaticData +一个计时器解决的。

在excel中手动执行时,宏运行完美但在尝试通过批处理和VBS自动执行时,我得到“运行时错误1004找不到bloombergui.xla ...”。

任何想法如何解决这个问题?我想我已经用尽谷歌的所有选项。

宏:

Sub UpdateWeekly()

Application.Run "bloombergUI.xla!RefreshAllStaticData"
Application.OnTime (Now + TimeValue("00:00:25")), "WeeklyPDF"

End Sub

Sub WeeklyPDF()

Application.ScreenUpdating = True

ActiveSheet.Range("A1:V225").Select
Selection.ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:="O:\LOCATION" & Format(Date, "MMMM-DD-YYYY") & " " & "Weekly", _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=False

Application.PrintCommunication = False

End Sub

VBScript中:

Dim args, objExcel

Set args = WScript.Arguments
Set objExcel = CreateObject("Excel.Application")

objExcel.Workbooks.Open args(0)
objExcel.Visible = True

objExcel.Run "UpdateCreditWeekly"

objExcel.ActiveWorkbook.Close(0)
objExcel.Quit
excel vba excel-vba bloomberg
2个回答
0
投票

当Excel以编程方式实例化时,Bloomberg加载项无法加载...我认为您需要每次都重新加载它。

在调用Application.Run "bloombergUI.xla!RefreshAllStaticData"之前确保AddIn在那里

    Sub UpdateWeekly()
        Dim blpAddin As Workbook
        On Error Resume Next
        Set blpAddin = Workbooks("bloombergUI.xla")
        On Error GoTo 0
        If Not blpAddin Is Nothing Then ' Check if add-in is loaded or not 
            Application.Run "bloombergUI.xla!RefreshAllStaticData" ' refresh Bloomberg formulas
            Application.OnTime (Now + TimeValue("00:00:25")), "WeeklyPDF" ' wait till bloomberg Formulas calculation complete
        Else
            Debug.Print "Bloomberg Add-in is not loaded"
        End If
    End Sub

如果没有加载项,则需要添加/加载加载项

    'To load the Add-in
    Application.Addins.Add(file path & name)

要么

    AddIns("Add-In Name").Installed = True

0
投票

我相信你的语法不正确。

Application.Run可用于运行用Visual Basic或Microsoft Excel宏语言编写的宏,或用于在DLL或XLL中运行函数。

您指定的宏可以是具有宏名称的字符串,也可以是指示函数所在位置的Range对象,或者是已注册DLL(XLL)函数的寄存器ID。如果使用字符串,则将在活动工作表的上下文中计算字符串。

此外,如果您使用的是较新版本的Excel,您将会遇到更多问题,因为我认为XLA是一种较旧的文件类型,因为它被XLAM取代。

有关更多信息,请参阅下面的链接,尤其是this one和this one。


更多信息:

© www.soinside.com 2019 - 2024. All rights reserved.