- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-06-21 12:47 PM
I'm new in BluePrism and I have the following scenario. There is an excel with 2 pivot tables. I need to change the filter, apply refresh and save the excel with the updated values in order to send as an attachment via email. Object MS Excel VBO - Extended doesn't seem to work properly for that work (I understand 'Add Criteria to Page Field for Pivot Table' action is only for creation and not in an already created pivot?), therefore I ended up trying my lock with Code stage. Unsuccessfully though so far. RefreshTable seems to work fine if I go first in the excel and uncheck the option 'Refresh data when opening the file', otherwise it gives me an error while opening the workbook. The problem is that the excel is exported with 'Refresh data when opening the file' checked.
I tried the below code but no luck so far:
Dim ws As Object
ws = GetWorksheet(Handle, Workbook, Worksheet)
ws.Activate()
ws.AutoFilterMode = False
ws.PivotTables(PivotTableName).PivotFields(Field).CurrentPage = Criteria
ws.PivotTables(PivotTableName).RefreshTables
Input Parameters:
Handle (Number) = 1
Workbook (Text) - The name of the workbook
Worksheet (Text) - The name of the worksheet
PivotTableName (Text) - The name of the pivot table
Field (Text) - The name of the field that filter applies
Criteria (Text) - The value for the filter that I want to apply
Any Ideas are most welcome! Thanks in advance!
#pivottable #pivotfilter #pivotrefresh
------------------------------
Theodoros Papasotiriou
------------------------------
Answered! Go to Answer.
Helpful Answers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-06-21 06:40 PM
Hi Theodoros,
While I checked stackoverflow for the error it indicates that the error is due to incorrect name of field but according to you it works when Refresh is turned off. So maybe you can try this before changing the Criteria and the turn it back to true at the end. Not sure if that'll work
ws.PivotTables("PivotTable2").PivotCache.RefreshOnFileOpen = False
------------------------------
Gopal Bhaire
Analyst
Accenture
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-06-21 01:55 PM
Hi Theodoros,
What error do you get when you try to open the file with your code?
------------------------------
Gopal Bhaire
Analyst
Accenture
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-06-21 02:12 PM
------------------------------
Theodoros Papasotiriou
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-06-21 06:40 PM
Hi Theodoros,
While I checked stackoverflow for the error it indicates that the error is due to incorrect name of field but according to you it works when Refresh is turned off. So maybe you can try this before changing the Criteria and the turn it back to true at the end. Not sure if that'll work
ws.PivotTables("PivotTable2").PivotCache.RefreshOnFileOpen = False
------------------------------
Gopal Bhaire
Analyst
Accenture
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
02-06-21 10:14 AM
Eventually it worked with the "Excel VBO-Extended" action "Add Criteria to Page Field Filter for Pivot Table" (code below)
Dim ws As Object
ws = GetWorksheet(Handle, Workbook, Worksheet)
ws.Activate()
ws.PivotTables(PivotTableName).PivotFields(Field).CurrentPage = Criteria
Input
Handle (Number) = 1
Workbook (Text) - The name of the workbook
Worksheet (Text) - The name of the worksheet
PivotTableName (Text) - The name of the pivot table
Field (Text) - The name of the field that filter applies
Criteria (Text) - The value for the filter that I want to apply
The problem was that within the PivotTable Options, the "Refresh data when opening the file" (under tab Data) was unchecked, therefore I needed to trigger a Refresh (PivotTable.RefreshTable) before applying the filter...
Now, I'm trying to change this value from the code ... Tried with your code above (I assume this is what it does), but before calling the function, when trying to Open Workbook in order to read the worksheet name, I get an error when "Refresh data when opening the file" is checked (it's like a deadlock)....Not sure if I can change the value without opening the workbook somehow
Thanks Gopal!
Best,
Theo
------------------------------
Theodoros Papasotiriou
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
02-06-21 12:02 PM
Hi Theodoros,
Are you getting error while opening workbook or while applying filter? I tried changing filter of sample excel with two pivot and it worked for me with "Refresh data when opening the file" checked. I added ws.PivotTables(PivotTableName).PivotCache.Refresh
at the very end of the code in 'Add Criteria to Page Field Filter for Pivot Table' code to refresh table after the criteria change.
My steps
1. Create Instance
2. Open Workbook
3. Add Criteria to Page Field Filter for Pivot Table
4. Close All Instance (with save)
I would recommend you record a macro from the Developer tab of Excel to check if the field name and everything is all right.
Thanks,
------------------------------
Gopal Bhaire
Analyst
Accenture
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
02-06-21 01:41 PM
Unfortunately I get the error much before the 'Add Criteria to Page Field Filter for Pivot Table'.
I follow the same order as yours. Error comes on Open Workbook: "HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER)".... When I uncheck manually the "Refresh data when opening the file" it works fine. However, the excel that I will process with my solution comes with the property checked. Therefore I'm trying to apply a code to uncheck that property before calling the Open Workbook (unsuccessfully so far)
Thanks again!
------------------------------
Theodoros Papasotiriou
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
02-06-21 01:53 PM
------------------------------
Gopal Bhaire
Analyst
Accenture
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
02-06-21 05:06 PM
------------------------------
Theodoros Papasotiriou
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
04-06-21 01:52 PM
Hi Theodoros,
If you are okay with adding libraries you can try this, I was working on creating a VBO with ClosedXML, I added an Update Pivot Criteria action which you can try.
OpenWorkBook ->Update Pivot Criteria->Close Workbook
Thanks,
------------------------------
Gopal Bhaire
Analyst
Accenture
------------------------------
