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
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