VBA in 2010 to select each Slicer Item then Call/ Run another Macro to pdf to email before repeating with the next Slicer Item etc

FLEMINGH

New Member
Joined
Aug 24, 2017
Messages
2
Hi,
Im yet to go on a VBA course, however Ive managed to find a VBA code to pdf a report in Excel 2010 and automatically send it via email.
However, now the report is a bit more dynamic - the pivot table is linked from Access and Im using a 'Slicer' to individualise each report that is to be sent out.
At any given point there will be between 80-90 Slicer Items (and therefore 80-90 individual reports) that will need to be selected in the VBA code - one at a time - and use the Macro to pdf to email.
Im stuck. I have the code below. However, it stops on the first Slicer Item. It doesn't loop to the next one.
Please help!!

Function MyFunction()
Application.Run "'Account Manager Report.xlsm'!create_and_email_pdf"
Exit Function
End Function


Dim i As Long
Dim slItem As SlicerItem
Application.ScreenUpdating = False
With ActiveWorkbook.SlicerCaches("Slicer_Salesperson")
.SlicerItems(1).Selected = True
For Each slItem In .VisibleSlicerItems
If slItem.Name <> .SlicerItems(1).Name Then _
slItem.Selected = False
Next slItem
Call MyFunction
For i = 1 To .SlicerItems.Count
.SlicerItems(i).Selected = True
.SlicerItems(i - 1).Selected = False
Call MyFunction
Next i
End With
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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