Macro referencing filepath

shanezer

New Member
Joined
May 26, 2020
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hi All,

Ive spent days trying to work out how to get around an issue. Basically I have a formatting macro that then refreshes the pivot tables. The pivot table range moves for some reason so I had to record another macro to fix these. The problem now is I cant save the file anywhere else as it points to a filepath when correcting the pivot table range.
So as you can see if I try and save it anywhere the macro wont work because the sheet is saved somewhere else with the name Report.xlsm Any help will be very much appreciated as my heads wrecked with it.

See code below.
ActiveSheet.PivotTables("PivotTable64").ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"c:\StaffShared1\Budgets\Prof Services\Management Accounts\Management Acc Reports\40000\[Report.xlsm]YTD!C1:C13" _
, Version:=6)

ActiveSheet.PivotTables("PivotTable65").PivotSelect "Funding", xlButton, True
Range("I7").Select
ActiveSheet.PivotTables("PivotTable65").ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"c:\StaffShared1\Budgets\Prof Services\Management Accounts\Management Acc Reports\40000\[Report.xlsm]FY!C1:C13" _
, Version:=6)
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Take
"c:\StaffShared1\Budgets\Prof Services\Management Accounts\Management Acc Reports\40000\[Report.xlsm]FY!C1:C13" _
, Version:=6)
and make it
"FY!C1:C13" _
, Version:=6)

just take out the file path and name.
 
Upvote 0
Take
"c:\StaffShared1\Budgets\Prof Services\Management Accounts\Management Acc Reports\40000\[Report.xlsm]FY!C1:C13" _
, Version:=6)
and make it
"FY!C1:C13" _
, Version:=6)

just take out the file path and name.
cheers will try this thankyou so much
 
Upvote 0
cheers will try this thankyou so much
Hi, have tried this and all pivot tables data has fully removed when i reference it like this. Even when I try and record a change of pivot range it still reverts back to this. For some reason the pivot table range decides to move to blank rows therefore pivot table doesnt work. This time even when I record it again and paste it in as you advised it doesnt work at all. Any advice much appreciated.
 
Upvote 0
I have a spreadsheet that I do this for weekly. Here is my code - there are some differences...

My macro creates a new duplicate sheet, clears it, renames it, and refreshes the pivot tables. I put code for one pivot table here, but there are four more.
VBA Code:
 shname = "Week  of " & m & "-" & d & "-" & y
    ActiveSheet.Name = shname
    
    ActiveSheet.PivotTables("PivotTable7").ChangePivotCache ActiveWorkbook. _
        PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        shname & "!R7C18:R22C19" _
        , Version:=6)
 
Upvote 0
I have a spreadsheet that I do this for weekly. Here is my code - there are some differences...

My macro creates a new duplicate sheet, clears it, renames it, and refreshes the pivot tables. I put code for one pivot table here, but there are four more.
VBA Code:
 shname = "Week  of " & m & "-" & d & "-" & y
    ActiveSheet.Name = shname
   
    ActiveSheet.PivotTables("PivotTable7").ChangePivotCache ActiveWorkbook. _
        PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        shname & "!R7C18:R22C19" _
        , Version:=6)
Thanks, I had to redo the pivot range recording, this has worked. Many thanks. No idea why the pivot range changes though in the first place on mine.
 
Upvote 0

Forum statistics

Threads
1,213,530
Messages
6,114,162
Members
448,554
Latest member
Gleisner2

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