Slobodan emailed me to describe a trick to protect Excel tables that he is using to drive data validation lists. The data validation lists are sourced from tables loaded via Power Query, and leverage a little hack to hide them from prying users eyes. I thought it would be cool if he shared it with everyone, so asked him to write up a little blog post on it, and here it is!
Take it away Slobodan…
Recently, my team and I had faced a problem with refreshing PQ tables that we managed to solve with a simple trick (no VBA coding), and shared it with Ken who asked me to share it with community. Thank you Ken for this opportunity! Glad to make some kind of contribution, to all of you PQ users.
We created calculation model for our sales people (Full cost calculation). Inside this Excel file, they have a lots of drop down lists from which they can choose customer, partner etc. The idea is to make these dropdown lists dynamic. In other words, whenever a new customer is created in SAP, they should be able to select this customer in Excel using a dropdown list. This is where Power Query comes to the rescue.
We have scheduled daily export of all our customers from SAP to a file on a network drive, and use this file as the data source for a local PQ table in the workbook. We then use our Power Query table “Customers” as the source for dropdown lists in calculation model.
How to make it fully automated? We have two goals here:
- We want Power Query to be scheduled for automatic refresh on a daily basis
- At the same time, we would like to protect Excel tables sourced via Power Query from careless users
For the first point, we have Power Update - a tool which allows you to schedule daily refresh.
Note from Ken: I haven't seen Slobodan's model, so there may be a need to use Power Update to do what he's doing. If you only need your Power Queries to update each time the Excel workbook is opened, however, you could force an update by changing the table's connection properties to force an update upon open.
Second issue, in order to protect Power Query table, we need to hide these sheets and protect the workbook. The end result is that our Customers table is hidden and cannot be unhidden and everything looks promising.
Of course, Excel protects the whole workbook structure using this method, which causes Power Update to fail. In fact, query refreshes also fail if we try to refresh data manually.
So the obvious solution doesn't work. I spent time Googling for solution to this but could not find one 🙂
I am not VBA guy, but I remembered one tip from Mynda Treacy’s dashboard course which I applied here.
- Hide the worksheet and open the Visual Basic Editor (press Alt+F11)
- In the Project Explorer Window (Ctrl + R if it's not showing) select the sheet which contains the Power Query table
- In the Properties Window (press F4 to display this), set the Visible property to "2 - xlSheetVeryHidden"
- Go to Tools --> VBAProject Properties --> Protection
- Check the box next to "Lock Project for Viewing"
- Set a password so only you can access it
- Close the Visual Basic Editor
Our sheet containing the Customers table is hidden, and there is no possibility to unhide it. It doesn't even show up in the menu!.
At this point the only way to unhide the worksheet is to go into the Visual Basic Editor, and reset the worksheet's Visible property - but you protected the VBA project with a password so no one can get in there.
The great thing is that refreshing the Power Query tables will work, because you didn’t actually lock the workbook structure.
This solution is intended to protect data from regular excel users, who can easily mess up your workbook. Do be aware that users with VBA skills will be able to break the password, or extract the hidden sheet contents.
Hopefully someone finds this useful 🙂