Killing connection in EXCEL vba

前端 未结 2 1215
庸人自扰
庸人自扰 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:10

    Why not using the built-in enumerator of the connections collection?

    Public Sub DeleteAllConnectionsInWorkbook()
        Dim aConn as Object
        For Each aConn in ActiveWorkbook.Connections
            aConn.Delete
        Next aConn
    End Sub
    

提交回复
热议问题