Killing connection in EXCEL vba

前端 未结 2 1244
庸人自扰
庸人自扰 2021-01-18 03:46

I am trying to removeconnection from my work book but I am still geting run-time error 5. I dont know what to do because in my other projects it works.

Thanks for ad

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-18 04:08

    You could try this in the for loop for deleting, using the minimal index 1 (One = 2/2) in VBA in place of i variable:

    ActiveWorkbook.Connections.Item(1).Delete
    

    Instead of

    ActiveWorkbook.Connections.Item(i).Delete
    

    As you delete, ActiveWorkbook.Connections.Count() will diminish, Some .item(i) does no more exist.

    Or this:

     '~~>kill all connections
        For i = ActiveWorkbook.Connections.Count To 1 Step -1
            ActiveWorkbook.Connections.Item(i).Delete
        Next
    

提交回复
热议问题