Hello,
I have a pivot table in Excel.
I created a loop that selects 1 filter of the pivot table.
For each loop it creates a PDF on my desktop, then takes it as an attachment, sends an email in outlook, deletes the PDF, then goes to the next filter on the pivot table.
Its probably sending 300 to 400 emails.
It works great.
The problem i am having is that once the email is in outlook, i believe the email servers (either mine or the recipients) is not delivering all the emails because it thinks its spam.
Who sends so many emails... with an attachment... SPAM People.
I tried to add a wait period on the loop, not sure if it did it properly, but i don't see the excel to outlook slowing down.
Sub Loop_PivotItems()
Dim FileName As String
Dim WSHShell As Object
Dim DesktopPath As String
Set WSHShell = CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
Set WSHShell = Nothing
'Loop through every PivotItem in the PageField (Filter) of the Pivot Table
For Each PivotItem In ActiveSheet.PivotTables(1).PageFields("Customer for statements").PivotItems
'Select the PivotItem
ActiveSheet.PivotTables(1).PageFields("Customer for statements").CurrentPage = PivotItem.Value
'Do whatever you need here....
If ActiveWindow.SelectedSheets.Count > 1 Then
MsgBox "There is more then one sheet selected," & vbNewLine & _
"ungroup the sheets and try the macro again"
Else
'For a fixed range use this line
FileName = RDB_Create_PDF(Range("A:I"), DesktopPath & "\" & Range("J1").Value, True, False)
If FileName <> "" Then
RDB_Mail_PDF_Outlook FileName, Range("J2").Value, Range("J1").Value, _
Range("J3").Value _
& vbNewLine & Range("J4").Value, True
Else
MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
"Microsoft Add-in is not installed" & vbNewLine & _
"You Canceled the GetSaveAsFilename dialog" & vbNewLine & _
"The path to Save the file in arg 2 is not correct" & vbNewLine & _
"You didn't want to overwrite the existing PDF if it exist"
End If
End If
Application.Wait (Now + TimeValue("0:00:03"))
Kill FileName
Application.Wait (Now + TimeValue("0:00:03"))
Next
MsgBox "Mail send - thanks ", vbInformation, "We are going global"
End Sub
------------------
Here is the message error i am getting. from outlook.
Your message did not reach some or all of the intended recipients.
The following recipient(s) cannot be reached:
'xxxxx@xxxx.com' on 3/19/2020 5:37 PM
554 6.6.0 Error sending message for delivery.
I have a pivot table in Excel.
I created a loop that selects 1 filter of the pivot table.
For each loop it creates a PDF on my desktop, then takes it as an attachment, sends an email in outlook, deletes the PDF, then goes to the next filter on the pivot table.
Its probably sending 300 to 400 emails.
It works great.
The problem i am having is that once the email is in outlook, i believe the email servers (either mine or the recipients) is not delivering all the emails because it thinks its spam.
Who sends so many emails... with an attachment... SPAM People.
I tried to add a wait period on the loop, not sure if it did it properly, but i don't see the excel to outlook slowing down.
Sub Loop_PivotItems()
Dim FileName As String
Dim WSHShell As Object
Dim DesktopPath As String
Set WSHShell = CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
Set WSHShell = Nothing
'Loop through every PivotItem in the PageField (Filter) of the Pivot Table
For Each PivotItem In ActiveSheet.PivotTables(1).PageFields("Customer for statements").PivotItems
'Select the PivotItem
ActiveSheet.PivotTables(1).PageFields("Customer for statements").CurrentPage = PivotItem.Value
'Do whatever you need here....
If ActiveWindow.SelectedSheets.Count > 1 Then
MsgBox "There is more then one sheet selected," & vbNewLine & _
"ungroup the sheets and try the macro again"
Else
'For a fixed range use this line
FileName = RDB_Create_PDF(Range("A:I"), DesktopPath & "\" & Range("J1").Value, True, False)
If FileName <> "" Then
RDB_Mail_PDF_Outlook FileName, Range("J2").Value, Range("J1").Value, _
Range("J3").Value _
& vbNewLine & Range("J4").Value, True
Else
MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
"Microsoft Add-in is not installed" & vbNewLine & _
"You Canceled the GetSaveAsFilename dialog" & vbNewLine & _
"The path to Save the file in arg 2 is not correct" & vbNewLine & _
"You didn't want to overwrite the existing PDF if it exist"
End If
End If
Application.Wait (Now + TimeValue("0:00:03"))
Kill FileName
Application.Wait (Now + TimeValue("0:00:03"))
Next
MsgBox "Mail send - thanks ", vbInformation, "We are going global"
End Sub
------------------
Here is the message error i am getting. from outlook.
Your message did not reach some or all of the intended recipients.
The following recipient(s) cannot be reached:
'xxxxx@xxxx.com' on 3/19/2020 5:37 PM
554 6.6.0 Error sending message for delivery.