刷新Excel连接 [英] Refresh Excel connections

查看:374
本文介绍了刷新Excel连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图循环遍历我的Excel工作簿中的每个连接,并单独刷新每个连接,并在每次刷新之间捕获任何错误消息。但是,当尝试运行代码时,我收到类型不匹配错误:

I'm trying to loop through each connection in my Excel workbook and refresh each one individually and capture any error messages in between each refresh. However, I receive a 'Type-Mismatch' error when trying to run the code:

Private Sub btnRefreshConns_Click()
Dim cn As WorkbookConnection
Set cn = ActiveWorkbook.Connections.Count

For Each cn In Workbook.Connections

cn.Refresh

Next

End Sub

有人可以帮我吗? >

Could someone please assist me?

推荐答案

Private Sub btnRefreshConns_Click()
Dim cn As WorkbookConnection
'Remove this line --> Set cn = ActiveWorkbook.Connections.Count

For Each cn In ActiveWorkbook.Connections

    cn.Refresh

Next

End Sub

应该这样做。使用 For Each ,您不需要跟踪计数。

should do it. With For Each, you don't need to keep track of the count.

(注意:撇号'在VB中引用评论,所以你可以尝试评论违规行,看看会发生什么。)

(Note: apostrophes ' introduce comments in VB, so you can try commenting out offending lines to see what happens.)

编辑:循环需要参考 ActiveWorkbook 工作簿是一种类型,即什么样的东西 ActiveWorkbook 是。 ActiveWorkbook 是一个对象,您可以操作的实际操作。

edit: The loop needs to refer to ActiveWorkbook. Workbook is a type, i.e., what kind of thing ActiveWorkbook is. ActiveWorkbook is an object, an actual thing you can manipulate.

这篇关于刷新Excel连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆