Hi Guys,
I am trying to refresh an excel workbook but I am not able to do it without opening and passing refresh Hotkeys to it. I can’t open the workbook since this process fails if I have the Remote Desktop disconnected.
Is there a way I can refresh the workbook without opening or doing any UI Interactions?
Note: The excel is connected to SQL Server Database and I refresh it by clicking “Refresh All” in the data tab.
Sure. I am uploading the zip folder with two files. The workbook_to_refresh.xlsx is the one to be refreshed and the MOCK_DATA.csv is the mock data connected to the workbook with Powerquery.
The aim is to refresh the powerquery connections without opening the workbook using VBA.
Please let me know if you need anything else
Sorry if I am suggesting something out of discussion.
Why can’t you read the csv and write data to excel. You can make the excel as template and use write range to enter data into the required columns.
When you settle of macro you have to always make sure the macros are enabled in file and always make sure the macros file in present. The above solution will be much simpler.
@Ragu9060
The csv file I provided is actually sample file for powerquery. I sent it so that we can check if the macro is working fine.
I have about 10-11 SQL Server connections built in the original file to be refreshed and I transform the data with powerquery to get the relevant texts. Therefore, unfortunately, it would not be possible for me to use csv since csv does not support powerquery.
Guys, I have found the solution.
I created the vb file as usual with “Thisworkbook.refreshall” as the code in the sub.
After I ran the VBA script using the bot, I was getting the error that “this will cancel a pending data refresh”, which was causing a manual intervention from me every time.
Therefore, I went to query properties and disabled “Refresh Data in the Background” and the code works like a charm now.