I have sales global sales data in very large files which I need to filter by country and product and then analyze. Since I will need to perform this same analysis over and over again with different country/product combinations I am trying to do this with a macro.
This is what the macro does:
- Open the source files with global data;
- Filters the data;
- Copies it and pastes it into a workbook which houses the macro;
- Recalculates and refreshes the workbook and;
- Saves a copy of the file to another folder.
The macro appears to run fine and the files are being saved, however I am running into 2 problems on steps 4 and 5:
- The pivot tables do not seem to be refreshing - this may be because the second problem:
- All pivot tables in the saved copy still refer to the original file
I'd prefer to fix both problems by generating the copied file without links, but I'm also open to any bandaids that might allow me to force the copied file to link to itself (this doesn't seem to work when I do it manually).
I have the full code if you want to see it all, but because I suspect the issue is in how I'm saving the file I'll just paste that piece here. Let me know if you need to see another part of the macro. Any help would be much appreciated, thanks in advance.
Save Function:
Public Sub SaveAsCopy(filePath As String)
Dim updateStatus As Boolean
'Check current status of Alerts
updateStatus = Application.DisplayAlerts
'Turn off alerts
Application.DisplayAlerts = False
ThisWorkbook.Sheets.Copy 'creates new workbook without macros"
'The New workbook copy is now the Active workbook
'Delete Control Sheet
ActiveWorkbook.Sheets(1).Delete
'Save Macro free version and close
ActiveWorkbook.SaveAs Filename:=filePath, FileFormat:=51
ActiveWorkbook.Close
'Revert back to origional alert status
Application.DisplayAlerts = updateStatus
End Sub
Function Call:
Call SaveAsCopy(filePath)