以编程方式添加 VBA 引用



我正在尝试纠正各种Avaya应用程序版本的参考问题(由于不同用户的目录不同,参考文献丢失)。我们有多个版本正在运行,需要它适用于所有可能的版本,然后给出一个 错误 .到目前为止,我已经创建了以下内容以在开始时内联定义它们,但它不断抛出"编译错误:无效的外部过程"。我是编码新手,并尝试将此信息添加到已经存在的 VBA 安装程序中。

'Start Declarations
Dim cvsApp As New ACSUP.cvsApplication
Dim cvsConn As New ACSCN.cvsConnection
Dim cvsSrv As New ACSUPSRV.cvsServer
Dim Rep As New ACSREP.cvsReport
Dim Info As Object, Log As Object, b As Object
Dim logged As Boolean
'Start My Code
If Dir("C:Program Files (x86)AvayaCMS Supervisor R16", vbDirectory) <> 
vbNullString Then
    cvsApp.References.AddFromFile "C:Program Files (x86)AvayaCMS 
Supervisor R16ascApp.exe"
    cvsConn.References.AddFromFile "C:Program Files (x86)AvayaCMS Supervisor R16cvsCONN.dll"
    cvsSrv.References.AddFromFile "C:Program Files (x86)AvayaCMS Supervisor R16ascSRV.exe"
    Rep.References.AddFromFile "C:Program Files (x86)AvayaCMS Supervisor R16ascRep.exe"
    Catalog.References.AddFromFile "C:Program Files (x86)AvayaCMS Supervisor R16cvsctlg.dll"
    Else
    If Dir("C:Program Files (x86)AvayaCMS Supervisor R17", vbDirectory) <> vbNullString Then
        cvsApp.References.AddFromFile "C:Program Files (x86)AvayaCMS Supervisor R17ascApp.exe"
        cvsConn.References.AddFromFile "C:Program Files (x86)AvayaCMS Supervisor R17cvsCONN.dll"
        cvsSrv.References.AddFromFile "C:Program Files (x86)AvayaCMS Supervisor R17ascSRV.exe"
        Rep.References.AddFromFile "C:Program Files (x86)AvayaCMS Supervisor R17ascRep.exe"
        Catalog.References.AddFromFile "C:Program Files (x86)AvayaCMS Supervisor R17cvsctlg.dll"
        Else
        If Dir("C:Program Files (x86)AvayaCMS Supervisor R18", vbDirectory) <> vbNullString Then
            cvsApp.References.AddFromFile "C:Program Files (x86)AvayaCMS Supervisor R18ascApp.exe"
            cvsConn.References.AddFromFile "C:Program Files (x86)AvayaCMS Supervisor R18cvsCONN.dll"
            cvsSrv.References.AddFromFile "C:Program Files (x86)AvayaCMS Supervisor R18ascSRV.exe"
            Rep.References.AddFromFile "C:Program Files (x86)AvayaCMS Supervisor R18ascRep.exe"
            Catalog.References.AddFromFile "C:Program Files (x86)AvayaCMS 
Supervisor R18cvsctlg.dll"
            Else
                MsgBox ("ERROR: Avaya Files not found, Contact Admin")
        End If
    End If
End If

按下按钮时调用的子。

Sub Report_Run()
Call FixReference 'added this in - does it need to be?
Call Unhide
Call Clear_Report
Call Report_a
Call Hide
End Sub

编辑#2 - 这是我在工具部分构建的参考资料的原始代码。我们大多数人同时启动了多台服务器,因此它会调用 cms 服务器订单号(因此打开了第 3 台服务器等)。代码之前显示的设置窗口:

设置
开始日期: 10/15/2017结束日期: 10/21/2017技能:****服务器顺序:1ACD: 6

Dim cvsApp As New ACSUP.cvsApplication
Dim cvsConn As New ACSCN.cvsConnection
Dim cvsSrv As New ACSUPSRV.cvsServer
Dim Rep As New ACSREP.cvsReport
Dim Info As Object, Log As Object, b As Object
Dim logged As Boolean
Sub Clear_Report()
Sheets(Array("-1 (2)", "-2 (2)", "-3 (2)", "-4 (2)", "-5 (2)", "-6 (2)", "-7 (2)", _
    "-8 (2)", "-9 (2)", "-10 (2)", "-11 (2)", "-12 (2)", "-13 (2)", "-14 (2)", "-15 (2)", _
    "-16 (2)", "-17 (2)", "-18 (2)", "-19 (2)", "-20 (2)", "-21 (2)", "-22 (2)", "-23 (2)" _
    , "-24 (2)", "-25 (2)")).Select
Sheets("-1 (2)").Activate
Sheets(Array("-26 (2)", "-27 (2)", "-28 (2)", "-29 (2)", "-30 (2)", "-31 (2)", _
    "-32 (2)", "-33 (2)", "-34 (2)", "-35 (2)")).Select Replace:=False
Columns("A:AB").Select
Selection.ClearContents
Sheets("Auto").Select
End Sub
Sub Report_Run()
Call Unhide
Call Clear_Report
Call Report_a
End Sub

Public Sub Report_a()
Application.ScreenUpdating = 0

Call Move_down2

Sheets("Report Drop").Select
Range("b2:x4500").Select
Selection.ClearContents
Selection.Clear
Dim Serv As Integer
Dim Report As String
Dim Report2 As String
Dim B1 As String
Dim B2 As String
Dim B3 As String
Dim B1A As String
Dim B2A As String
Dim B3A As String
Dim ACDset As String
Dim B4 As String
Dim B4A As String
Dim Dropline As Integer
Serv = ThisWorkbook.Sheets("Auto").Cells(8, 2)
Report = ThisWorkbook.Sheets("Auto").Cells(2, 2)
'Report2 = ThisWorkbook.Sheets("Auto").Cells(51, 26)
'B1 = ThisWorkbook.Sheets("Auto").Cells(4, 2)
'B2 = ThisWorkbook.Sheets("Auto").Cells(5, 2)
'B3 = ThisWorkbook.Sheets("Auto").Cells(5, 26)
B1A = ThisWorkbook.Sheets("Auto").Cells(4, 3)
B2A = ThisWorkbook.Sheets("Auto").Cells(5, 3)
'B3A = ThisWorkbook.Sheets("Auto").Cells(8, 26)
Dropline = ThisWorkbook.Sheets("Auto").Cells(3, 2)

ACDset = ThisWorkbook.Sheets("Auto").Cells(9, 2)
Set cvsSrv = cvsApp.Servers(Serv) '(cvsApp.Servers.Count) '''''' we set a reference to the server here
Call Report_b(Report, ACDset, B1, B2, B3, B1A, B2A, B3A, B4, B4A)
ThisWorkbook.Sheets("Report Drop").Cells(Dropline, 2).PasteSpecial
logout
Application.ScreenUpdating = 1
    Sheets("Report Drop").Select
Range("A1:ab5000").Select
Selection.Copy
Sheets("-1 (2)").Select
Range("A1").Select
ActiveSheet.Paste

Application.ScreenUpdating = 1
Call Rep2
Sheets("Output").Select
End Sub
Sub Report_b(sReportName As String, ByVal ACDset As String, ByVal B1 As String, B2 As String, B3 As String, B1A As String, B2A As String, B3A As String, B4 As String, B4A As String)
On Error Resume Next
cvsSrv.Reports.ACD = ACDset ' In server03 ACD1=AD2  ACD2=KC ACD3=Core
Set Info = cvsSrv.Reports.Reports(sReportName)
If Info Is Nothing Then
If cvsSrv.Interactive Then
MsgBox "The Report " & sReportName & " was not found on ACD 1", vbCritical Or vbOKOnly, "CentreVu Supervisor"
Else
Set Log = CreateObject("ACSERR.cvslog")
Log.AutoLogWrite "The Report " & sReportName & " was not found on ACD 1"
Set Log = Nothing
End If
Else
b = cvsSrv.Reports.CreateReport(Info, Rep)
If b Then
Rep.Window.Top = 0
Rep.Window.Left = 0
Rep.Window.Width = 0
Rep.Window.Height = 0

Debug.Print Rep.SetProperty("Split/Skill(s)", B1A)
Debug.Print Rep.SetProperty("Date(s)", B2A)
Debug.Print Rep.SetProperty("Times", "00:00-23:30")
'Debug.Print Rep.SetProperty(B4, B4A)
b = Rep.ExportData("", 9, 0, True, False, True)
Rep.Quit
If Not cvsSrv.Interactive Then cvsSrv.ActiveTasks.Remove Rep.TaskID
Set Rep = Nothing
End If
End If
Set Info = Nothing
End Sub
Sub Rep2()
If ThisWorkbook.Sheets("Auto").Cells(6, 3) = "Y" Then Call Report_a
Sheets("Output").Select
'Call Macro4
Sheets("Output").Select
End Sub
Sub Hide()
'
Sheets("Report Drop").Visible = False
Sheets("-1 (2)").Visible = False
Sheets("-2 (2)").Visible = False
..(And so on)
'
End Sub
Sub Unhide()
'
Sheets("Report Drop").Select
Sheets("-1 (2)").Visible = True
..(And so on)
'
End Sub
Sub logout()
Set Log = Nothing
Set Rep = Nothing
Set cvsSrv = Nothing
Set cvsApp = Nothing
End Sub

您可以尝试替换 4 个早期绑定声明:

Dim cvsApp As New ACSUP.cvsApplication
Dim cvsConn As New ACSCN.cvsConnection
Dim cvsSrv As New ACSUPSRV.cvsServer
Dim Rep As New ACSREP.cvsReport

后期绑定并从项目中删除 Avaya CMS 主管引用:

Dim cvsApp As Object, cvsConn As Object, cvsSrv As Object, Rep As Object
Set cvsApp = CreateObject("ACSUP.cvsApplication")
Set cvsConn = CreateObject("ACSCN.cvsConnection")
Set cvsSrv = CreateObject("ACSUPSRV.cvsServer")
Set Rep = CreateObject("ACSREP.cvsReport")

抱歉,这太多了,无法放入评论中,但这不是"答案"。尝试运行这个小过程。在运行"即时"窗口时将其打开。也许它将帮助您了解需要做些什么来解决问题?


注意:如果无法识别Dim oRef As Reference

  • 添加对 VBIDE 的引用:ThisWorkbook.VBProject.References.AddFromGuid GUID:="{0002E157-0000-0000-C000-000000000046}", Major:=5, Minor:=3
  • 信任 VBA 项目对象模型 ( Options> Trust Center> Macro Settings

Public Sub getAppRef()
Dim oRef        As Reference
Dim sName       As String * 20
Dim sBroke      As String * 15
Dim sPath       As String * 150
Dim sVer        As String * 15
Dim sKind       As String * 10
Dim sGUID       As String * 45

    debug.print Now(), "Reference:"
    For Each oRef In Application.References
    'Clear Variables
        sName = ""
        sBroke = ""
        sPath = ""
        sVer = ""
        sKind = ""
        sGUID = ""
    'Populate Variables
        sName = "Name:" & oRef.Name
        sBroke = "IsBroken:" & oRef.IsBroken
        sPath = "Path:" & oRef.FullPath
        sVer = "Version:" & oRef.Major & "." & oRef.Minor
        sKind = "Kind:" & oRef.Kind
        sGUID = "GUID:" & oRef.Guid
        Debug.Print Now(), sName, sBroke, sVer, sKind, sGUID, sPath
    Next
End Sub

最新更新