'VBA code to update a SQL view connection and refresh pivot tables

I'm new to the world of VBA and I was hoping for some help. I've been tasked with updating an Excel workbook such that it pulls in a view from SQL server and updates a bunch of pivot tables. Usually I would do this in a very manual way:

  • Data > Get Data > From database > From SQL Server Database > find the view and create a connection > Refresh the pivots

How would I write a bit of VBA code such that it would do this for me? Note that the view will change so I thought that the best way to do this would be to specify a string and from extensive googling specify the UNC path which will be updated. No idea if this will work as I do not know where to begin with writing the code.

Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source