Query keeps “refreshing” even when vba code prevented

Alwexis

New Member
Joined
Jun 16, 2020
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Hello

I have a really strange problem with my excel web API query connection. It is suppose to download a file from API and it works really fine. However it should only do so when i click a button "Download". For this button i created a simple vba for a refresh:

VBA Code:
Public Sub CommandButton2_Click()

Application.DisplayAlerts = False

ThisWorkbook.Queries.FastCombine = True

ThisWorkbook.Connections("Query - Test").Refresh

End Sub

I also have a different button to refresh all other queries in my workbook. It has exact same vba code but of course with different query names and not including the one i mentioned above.

Now, when I open my excel file and click a button to refresh all other queries, the query "Query - Test" doesnt get refreshed and its ok. HOWEVER when queries finish refreshing, I still get a pop-up window to download this file, despite a query has not been refreshed! What makes it even more strange is that it happen ONLY when i click the refresh button for the first time. It never does it again unless I close and open my excel file again.

I put following vba code in modules to disable any possible refresh:

VBA Code:
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

... but I still get a download pop-up when i refresh the other connections for the first time... Is there any way i can prevent this happening?

Alex
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,215,035
Messages
6,122,791
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top