Data Source Change in Macro VB code

ggeleceng

New Member
Joined
Dec 10, 2014
Messages
2
Hello Excel Gurus :smile:, I have an issue in my macro code, when I run it on a PC other than mine

I digged to find the reason, I noticed the below:



Workbooks("Mastersheet.xlsm").Connections.Add2 _
"WorksheetConnection_RTP Summary!$B:$S", "", _
"WORKSHEET;C:\Users\Ggeleceng\Desktop\Mastersheet.xlsm]RTP Summary" _
, "RTP Summary!$B:$S", 7, True, False
ActiveWorkbook.PivotCaches.Create(SourceType:=xlExternal, SourceData:= _
ActiveWorkbook.Connections("WorksheetConnection_RTP Summary!$B:$S"), Version _
:=xlPivotTableVersion15).CreatePivotTable TableDestination:= _
"DashBoard!R12C17", TableName:="PivotTable2", DefaultVersion:= _
xlPivotTableVersion15


I need help on how to make the Macro runs on other machines, on other words, how I can modify the pivot table source in the above underlined code to read the data from any machine the macro runs on....

Note: all my data are embedded within the same workbook tabs, no external data

Thanks in advance
 

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.
Is that code in the Mastersheet.xlsm workbook?
 
Upvote 0
This is a bit of a guess, but try something like this.

Code:
[COLOR=#ff0000]ThisWorkbook.[/COLOR]Connections.Add2 _
"WorksheetConnection_RTP Summary!$B:$S", "", _
"WORKSHEET;[COLOR=#ff0000]" & ThisWorkbook.FullName & "][/COLOR]RTP Summary" _
, "RTP Summary!$B:$S", 7, [COLOR=darkblue]True[/COLOR], [COLOR=darkblue]False[/COLOR]
ActiveWorkbook.PivotCaches.Create(SourceType:=xlExternal, SourceData:= _
ActiveWorkbook.Connections("WorksheetConnection_RTP Summary!$B:$S"), Version _
:=xlPivotTableVersion15).CreatePivotTable TableDestination:= _
"DashBoard!R12C17", TableName:="PivotTable2", DefaultVersion:= _
xlPivotTableVersion15
 
Upvote 0
Then AlphaFrog's amendments should work for you.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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