I need to send product in PDF, I found the following code, works great until I add MyArr. MyArr is list of email address for the To: block. Now I get Compile Error: ByRef Argument Type Mismatch and not sure how fix. Thanks
Sub Send_Slides()
Dim FileName As String
Dim MyArr As Variant
MyArr = ThisWorkbook.Sheets(“recap”).Range(“q1:q100”)
'Call the function with the correct arguments
FileName = Create_PDF(ActiveWorkbook, “C:\Slides\Daily Slides\" + Worksheets(“recap”).Range(“j3”), True, False)
If FileName <> "" Then
Mail_PDF_Outlook FileName, MyArr, “Daily Slides " + Worksheets(“recap”).Range(“j1”), _
“ALCON, " _
& vbNewLine & vbNewLine & “Daily Slides for " + Worksheets(“recap”).Range(“j1”) + " attached." _
& vbNewLine & vbNewLine & "", False
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 Sub
Function Mail_PDF_Outlook(FileNamePDF As String, StrTo As String, _
StrSubject As String, StrBody As String, Send As Boolean)
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject(“Outlook.Application”)
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = StrTo
.CC = ""
.BCC = ""
.Subject = StrSubject
.Body = StrBody
.Attachments.Add FileNamePDF
If Send = True Then
.Send
Else
.Display
End If
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Function
Sub Send_Slides()
Dim FileName As String
Dim MyArr As Variant
MyArr = ThisWorkbook.Sheets(“recap”).Range(“q1:q100”)
'Call the function with the correct arguments
FileName = Create_PDF(ActiveWorkbook, “C:\Slides\Daily Slides\" + Worksheets(“recap”).Range(“j3”), True, False)
If FileName <> "" Then
Mail_PDF_Outlook FileName, MyArr, “Daily Slides " + Worksheets(“recap”).Range(“j1”), _
“ALCON, " _
& vbNewLine & vbNewLine & “Daily Slides for " + Worksheets(“recap”).Range(“j1”) + " attached." _
& vbNewLine & vbNewLine & "", False
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 Sub
Function Mail_PDF_Outlook(FileNamePDF As String, StrTo As String, _
StrSubject As String, StrBody As String, Send As Boolean)
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject(“Outlook.Application”)
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = StrTo
.CC = ""
.BCC = ""
.Subject = StrSubject
.Body = StrBody
.Attachments.Add FileNamePDF
If Send = True Then
.Send
Else
.Display
End If
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Function