Oct 13 2022 12:48 AM
Hi guys,
I'm stuck with this code, tried everywhere with no luck.
My sheet:
What I would like to do:
I have all of the code ready, just the one where I need get them in the VBA. I'm stuck on line 20 to create a range called EmailTo and insert that in line 33
Sub PrintSendStore()
Dim Oapp As Outlook.Application
Dim Omail As Object
storecnt = 1
Do While storecnt <= Range("SharePoint[STORE_NAME]").Rows.Count
StoreName = Range("SharePoint[[#All],[STORE_NAME]]").Offset(storecnt, 0)
Sheet3.Range("D5").Value = StoreName
Filename = Sheet3.Range("D5").Value & " - " & Format(Sheet3.Range("D9").Value, "MMMM YYYY") & ".pdf"
FileName2 = Sheet3.Range("D5").Value & " - " & Format(Sheet3.Range("D9").Value, "MMMM YYYY")
Sheet3.ExportAsFixedFormat xlTypePDF, ThisWorkbook.Path & "/" & Filename
'EmailTo =
Set Oapp = New Outlook.Application
Set Omail = Oapp.CreateItem(0)
Oapp.Session.Logon
Dim last_row As Integer
Dim i As Integer
last_row = Application.WorksheetFunction.CountA(Sheet3.Range("O:O"))
With Omail
.To = EmailTo ' Sheet3.Range("O2").Value (TO EMAIL TO SINGLE PERSON)
.Subject = "Monthly Meeting template: " & FileName2
.Body = "Hi " & Sheet3.Range("P2") & "," & vbCrLf & vbCrLf & _
"Please find attached your Monthly Store Operational Meeting Template." & vbCrLf & vbCrLf & _
"Kind Regards" & vbCrLf & vbCrLf & _
"Admin"
.Attachments.Add (ThisWorkbook.Path & "/" & Filename)
.display
End With
storecnt = storecnt + 1
Loop
Set Oapp = Nothing
Set Omail = Nothing
End Sub