0

Whenever I change windows of opened workbooks and come back to MyFile.xlsb where I have defined external connection, the refresh of all pivot tables in MyFile.xlsb runs automatically. Needless to add it is very annoying feature. How to disable it? How to run refresh all only on demand. Important note. This problem occurs only on computers of the users I distribute MyFile.xlsb. On my computer it works ok.

I have defined the external connection as a reference to stored procedure in SQL.

Usage

Definition

Connection string:

Provider=SQLOLEDB.1;
Integrated Security=SSPI;
Persist Security Info=True;
Initial Catalog=MyDataBase;
Data Source=MyServerName;
Use Procedure for Prepare=1;
Auto Translate=True;
Packet Size=4096;
Workstation ID=MyWorkstationID;
Use Encryption for Data=False;
Tag with column collation when possible=False

Here is SQL stored procedure I call.

CREATE PROCEDURE [dbo].[MyProcedure]
AS
BEGIN

-- part one, show user what he has to see
SELECT *
FROM [dbo].[MyView] 
ORDER BY 1

-- part two, get user data
INSERT INTO dbo.My_other_table_logins_history
SELECT 
GETDATE(), 
ORIGINAL_LOGIN()
END

The concept of using this procedure is explained here: SQL procedure from Excel run from connection properties with user login as parameter

4
  • Check to see if there is a macro in the workbook that refreshes all. Commented Sep 7, 2015 at 13:37
  • @rwking no there is none. I disabled all events. I also unchecked everything in usage pane. Commented Sep 7, 2015 at 13:53
  • Have you checked Excel settings on users computers ? Commented Sep 9, 2015 at 20:20
  • Have a look here: msdn.microsoft.com/en-us/library/office/ff821120.aspx You can disable automatic refresh. Commented Sep 9, 2015 at 20:25

1 Answer 1

1
+50

Try running this:

Option Explicit

Public Sub disableAutoRefreshConnection()
    Dim cnn As WorkbookConnection

    For Each cnn In ActiveWorkbook.Connections
        With cnn.OLEDBConnection
            .BackgroundQuery = False
            If .Refreshing Then .CancelRefresh
            .EnableRefresh = False
            .RefreshOnFileOpen = False
            .RefreshPeriod = 0
        End With
    Next
End Sub

BackgroundQuery    Default: True;     If queries are asynchronous

CancelRefresh                         Cancels refresh operations in progress

EnableRefresh      Default: True;     If connection can be refreshed by the user

RefreshOnFileOpen  Default: False;    If it auto-updates each time workbook is opened

RefreshPeriod      Default: 0;        Number of minutes between refreshes
Sign up to request clarification or add additional context in comments.

3 Comments

It works. I think the key line of your code is .EnableRefresh = False Any ideas why refreshing procedure runs automatically?
I'd need to duplicate you're setup and monitor settings to see when it gets turned on, so I'll do some tests, but in the meantime you could disable each line, one at the time to confirm the one you mentioned. Also you can change it to act only on "MyServerName" instead of looping through all existing connections (if you have more than this one)
I duplicated your setup and used other connections as well but I wasn't able to see the issue (I used a small db). My guess is that one of the setting was changed from the default values - I added more info to the answer as a reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.