VBA to Prompt the Change Data Source dialog box of a Pivot Table

jobe24

New Member
Joined
May 10, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello,

I was wondering if there was a way to prompt the "Change Data Source" Dialog box of a specific pivot table found within a file? I have a macro file that rolls the contents for a new reporting period, and I wanted to end it with this prompt so the end user can select the new data source (which is found in another file) without having to manually click on "Change Data Source" to have the dialog box come up.

Is this possible?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
You can use the ExecuteMso method of the CommandBars object to execute the Ribbon command for changing the data source. First we need to find the id for the command. So select...

VBA Code:
File >> Options >> Customize Ribbon

Then select "All Commands" from the dropdown for "Choose commands from". Then scroll down until you find "Change Data Source", and move your cursor over it until a display pops up. As you'll see, the id for the command is "PivotTableChangeDataSource"...

change-data-source.png


Now you can use the following line of code to execute the command...

VBA Code:
application.CommandBars.ExecuteMso "PivotTableChangeDataSource"

Just make sure that your code first makes the sheet containing your pivottable the active sheet, and that any cell within pivottable is selected.

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,214,896
Messages
6,122,132
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top