Refresh:
Excel offers Refresh All by which we can refresh data coming or connected from external sources like Pivot Table. Refreshes all external data ranges and PivotTable reports in the specified workbook. To refresh follow the steps as given below:
- Navigate Data ribbon tab
- Locate Connection group
- Click on Refresh All dropdown menu
- Select Refresh All

You can apply the same using code as shown below (Note we are showing code example from VSTO Addin hence user is recommended to follow the prerequisites given below).
Prerequisites:
- Visual Studio 2015 or above having Microsoft Office for Developer Tool installed
- Create Excel Addin in C# or VB code style (Visual Studio Tools for Office)
- Excel 2010 or above
- Create a ribbon designer and put button
C# code example:
private void btnRefreshAll_Click(object sender, RibbonControlEventArgs e) { //get active workbook reference excel.Workbook oWorkbook = Globals.ThisAddIn.Application.ActiveWorkbook; //Refresh oWorkbook.RefreshAll(); }
VB.Net code example:
Private Sub btnRefreshAll_Click(sender As Object, e As RibbonControlEventArgs) Handles btnRefreshAll.Click 'get active workbook reference Dim oWorkbook as excel.Workbook oWorkbook=Globals.ThisAddIn.Application.ActiveWorkbook 'Refresh oWorkbook.RefreshAll() End Sub
VBA code example:
Public Sub RefreshAll() 'Bind workbook reference Dim oWorkbook As Workbook Set oWorkbook = ActiveWorkbook 'Refresh All oWorkbook.RefreshAll End Sub
Next >> Text to Columns Conversion in Excel