禁用工作簿连接

发布于 2024-12-11 03:36:09 字数 481 浏览 0 评论 0原文

我有一个 Excel 2007 .xltm 工作簿模板,其中有多个与 SQL Server 的连接。我没有将 xltm 的目录列为受信任位置,因此默认情况下外部连接被禁用。这很有效,因为我有宏(已签名且受信任),稍后可以在使用 Workbook_Open 进行一系列输入后启用这些连接。

但是,我最近将该目录添加为受信任位置,现在连接会自动刷新(无论 Connection.ODBCConnection.RefreshOnFileOpen 设置为 False..

)希望找到一个简单的命令,例如 ActiveWorkbook.DisableConnections (因为有一个 ActiveWorkbook.EnableConnections...)

我看到的只是只读ActiveWorkbook.ConnectionsDisabled...如何将其设置为 true?

I have an Excel 2007 .xltm workbook template with several connections to SQL Server. I did not list the xltm's directory as a Trusted Location, so by default, external connections were disabled. This works well, because I have macros (signed & trusted) that would later enable these connections after a series of inputs using Workbook_Open.

However, I recently added the directory as a trusted location, and now the connections refresh automatically (regardless of Connection.ODBCConnection.RefreshOnFileOpen being set to False..)

So, I was hoping to find a simple command such as ActiveWorkbook.DisableConnections (since there is an ActiveWorkbook.EnableConnections...)

All I see is the read-only ActiveWorkbook.ConnectionsDisabled... How do I set it to true?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北城孤痞 2024-12-18 03:36:09

想通了。完成文件修改后,我运行以下函数,这会阻止模板自动刷新数据。

Private Sub DisableConnections()
    Dim conn As Object
    For Each conn In ActiveWorkbook.Connections
        conn.ODBCConnection.EnableRefresh = False
    Next
End Sub

根据我的设置,我可能会将 ODBCConnection 替换为 OLEDBConnection

Figured it out. I run the following function once I'm done modifying the file, and this prevents the template from automatically refreshing the data.

Private Sub DisableConnections()
    Dim conn As Object
    For Each conn In ActiveWorkbook.Connections
        conn.ODBCConnection.EnableRefresh = False
    Next
End Sub

Depending on my setup, I might swap ODBCConnection for OLEDBConnection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文