# Export to Excel Automation Activity with Excel Pivot Tables - file locked

**URL:** <https://forums.toadworld.com/t/export-to-excel-automation-activity-with-excel-pivot-tables-file-locked/38259>\
**Category:** Toad Data Point & Toad Intelligence Central\
**Created:** [August 29, 2016, 8:17am UTC](https://forums.toadworld.com/t/export-to-excel-automation-activity-with-excel-pivot-tables-file-locked/38259 "2016-08-29T08:17:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andy.corson](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@andy.corson](https://forums.toadworld.com/u/andy.corson)\
**Post date:** [August 29, 2016, 8:17am UTC](https://forums.toadworld.com/t/export-to-excel-automation-activity-with-excel-pivot-tables-file-locked/38259/1 "2016-08-29T08:17:45Z")

</div>

I work a lot with exporting data to Excel files that contains pivot tables, and have been working through a few issues after upgrading to TDP 4.0. I wanted to share an additional issue that popped up and how I resolved it. Many of my Excel docs are macro-enabled. I came across 1 issue today where my automation script would hang and issue a message stating that the Excel file was locked. I realized that this was due to 1 of my pivot tables that had the option checked to refresh data when opening the file. I set my pivot tables to not refresh on opening the file, and changed to using a macro to refresh the pivot table cache. Here is the code I used:

Sub macro\_name()  
With Sheets(“Sheet name”).PivotTables(1)  
.PivotCache.Refresh  
End With  
End Sub

I set this macro to run after export.

---

<div class="post-metadata">

**Author:** ![Debbie\_Peabody](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/debbie_peabody/32/18_2.png) [@Debbie\_Peabody](https://forums.toadworld.com/u/Debbie_Peabody)\
**Post date:** [August 29, 2016, 8:36am UTC](https://forums.toadworld.com/t/export-to-excel-automation-activity-with-excel-pivot-tables-file-locked/38259/2 "2016-08-29T08:36:12Z")

</div>

Thats interesting. Was the automation script using multiple activities to populate multiple worksheets?

---

<div class="post-metadata">

**Author:** ![andy.corson](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@andy.corson](https://forums.toadworld.com/u/andy.corson)\
**Post date:** [August 29, 2016, 8:53am UTC](https://forums.toadworld.com/t/export-to-excel-automation-activity-with-excel-pivot-tables-file-locked/38259/3 "2016-08-29T08:53:26Z")

</div>

I have 3 Export activities set up in parallel, each exporting to multiple sheets.
