web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Use variable to identi...
Power Apps
Unanswered

Use variable to identify which query to refresh? (Excel, VBA, PowerQuery)

(1) ShareShare
ReportReport
Posted on by

I'm rebuilding some old reports that have gotten slow, and am using queries rather than multiple connections to the same server and database this time.

 

In the original and new versions, each report has a bunch of tabs, and each tab has two buttons that run macros: one to refresh the data in that specific tab, and one to clear the data.  This time I'd love to create only one piece of VBA code to refresh the query for the active worksheet, and pass a variable into it that identifies which query that should be.  Doing that to clear the data is simple, but I haven't figured out a way to refresh.

 

For each query I've used Get Data > From Database > SQL, pasted in my query, hit Transform, and given it a specific name.  Of course, hitting Close & Load the first time creates the tab for me and gives it the name of the query.  It's simple enough to write a worksheet's name into a variable (I named mine the very original "sheetNm",) but how can I pass that variable into the refresh command?

 

This is an example what I'm working with:

ActiveWorkbook.Connections("Query - Fourth_Tab-L").Refresh

 

Naturally, I can't replace the name of the query with the name of the variable, that just triggers a subscript out of range error.  Have any of you ever done this successfully?

 

Thanks for your time!

Categories:
I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 528

#2
WarrenBelz Profile Picture

WarrenBelz 426 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 306

Last 30 days Overall leaderboard