Multifunction Macro fails

robartle

New Member
Joined
Sep 23, 2011
Messages
1
Hi all,

I have a macro here that is mostly working. What it is supposed to do is copy the workbook to a network drive, cut open database connections and then refresh all pivots. I've had it so it will do all that when saving to a local drive but when I changed it to save to the network drive it fails to cut the connections. I'm not sure if it refreshes the pivots. Any help would be appreciated.

Here's the code:

Declare Function SetCurrentDirectoryA Lib "KERNEL32" (ByVal lpPathName As String) As Long

Sub AQW_Report()
'
'Refreshes all pivots and cuts connections to Access DB.
'

'Saves the open template to a network drive as a new timestamped workbook.
SetCurrentDirectoryA "\\Ustpa2gtsfp03\L&d\Spq\PRC Team\Reporting\Audit Quality Workshop (AQW) 2011\AQW-PCS\Delivered"
ActiveWorkbook.SaveAs Filename:= _
"\\Ustpa2gtsfp03\L&d\Spq\PRC Team\Reporting\Audit Quality Workshop (AQW) 2011\AQW-PCS\Delivered\AQW PCS 2011 REPORT " & Format(Now, "yyyymmdd hhmm") & ".xlsm" _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

'Loops through all the connections in the book and cuts them.
For i = 1 To ActiveWorkbook.Connections.Count
If ActiveWorkbook.Connections.Count = 0 Then Exit Sub
ActiveWorkbook.Connections.Item(i).Delete
i = i - 1
Next i

'Refresh all pivot tables.
ActiveWorkbook.RefreshAll
Sheets("MarketSummary").Select
ActiveSheet.PivotTables("MarketSumm_Pvt").PivotCache.Refresh
Sheets("TeamSummary").Select
ActiveSheet.PivotTables("TeamSumm_Pvt").PivotCache.Refresh
Sheets("Activity Summary").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh



End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,224,802
Messages
6,181,054
Members
453,014
Latest member
Chris258

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