禁用“ Analysis Services Connection 14.0”对话框

时间:2019-05-30 15:59:14

标签: excel vba olap oledbconnection

由于用户凭据或权限,想捕获OLEDBConnection上的任何错误,但是MSOLAP.8(“ Analysis Services Connection 14.0”)始终提示您输入正确的设置。作为一种解决方法,我可以根据需要的行为降级到MSOLAP.7。

环境为Excel 365中的VBA。除非用户在对话框中单击“取消”,否则MSOLAP.8不会触发可捕获的错误。希望避免出现此对话框,因为它包含可能会使某些用户感到困惑的设置(服务器,多维数据集)。

我尝试了以下语句但没有成功禁用对话框...

    Application.EnableEvents = False
    Application.DisplayAlerts = False

...以及查看所有MSOLAP.8连接参数以寻找可能的解决方案。

Private Sub btn_Refresh_Click()

    On Error GoTo connection_error

    Application.EnableEvents = False
    Application.DisplayAlerts = False

    With ActiveWorkbook.Connections("xxx").OLEDBConnection
        .CommandText = Array("xxx")
        .CommandType = xlCmdCube
        .Connection = Array( _
        "OLEDB;Provider=MSOLAP.8;Password=""" & Me.txt_Pwd & """;Persist Security Info=True;User ID=" & Me.txt_User & ";Catalog=xxx;Data Source=http" _
        , _
        "://xxx.xxx.xxx.xxx.xxx:xxx/xmla/default;MDX Compatibility=1;Safety Options=2;MDX Missing Member Mode=Error;Update " _
        , "Isolation Level=2")
        .RefreshOnFileOpen = False
        .SavePassword = False
        .SourceConnectionFile = ""
        .MaxDrillthroughRecords = 1000
        .ServerCredentialsMethod = xlCredentialsMethodNone
        .AlwaysUseConnectionFile = False
        .RetrieveInOfficeUILang = True
    End With

    With ActiveWorkbook.Connections("xxx")
        .Name = "xxx"
        .Description = "xxx"
    End With

    ActiveWorkbook.Connections("xxx").OLEDBConnection.MakeConnection

    ActiveWorkbook.Connections("xxx").Refresh

    Unload Me
    Exit Sub

connection_error:
    MsgBox "You have either entered the wrong ID and password, or you do not have permission to view this data."
End Sub

0 个答案:

没有答案