Excel 2013 - 针对多个wksheets w / i工作簿的Web Query连接字符串修改

时间:2015-12-11 18:43:02

标签: excel-vba vba excel

我需要修改大约60个工作表 - 连接字符串以更改1个标准。我在堆栈溢出时发现此代码,但是,我得到运行时错误1004:应用程序定义或对象定义错误。见(*)

    Sub ConnectionString_modify()
    Dim i As Long
    Dim cnt As Long
    Dim modtext As String
    Dim modrange As String
    Dim conn
    'Grab nummber of workbook connections
    cnt = ActiveWorkbook.Connections.Count


    For i = cnt To 1 Step -1
    Set conn = ActiveWorkbook.Connections.Item(i)
    modtext = conn.OLEDBConnection.Connection '**********
    modtext = VBA.Replace(modtext, "quickRange=NEXT_3_DAYS", "quickRange=PLUS_MINUS_3_DAYS")
    conn.OLEDBConnection.Connection = modtext
    conn.Name = VBA.Replace(conn.Name, "quickRange=NEXT_3_DAYS", "quickRange=PLUS_MINUS_3_DAYS")

    Next i

    End Sub

1 个答案:

答案 0 :(得分:0)

我的机器上没有Excel可供检查,但我想您需要调用正确的方法来获取字符串,例如

modtext = OLEDBConnection.ConnectionString

而不是

modtext = OLEDBConnection.Connection