TheNoodle
TheNoodle

Reputation: 77

Disabling Workbook Connections

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?

Upvotes: 1

Views: 6562

Answers (1)

TheNoodle
TheNoodle

Reputation: 77

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.

Upvotes: 2

Related Questions