现在,我在一张名为" gebruikers"的工作表中列出了一个人员。每个用户在此列表中都有一个电子邮件地址。
我现在所做的是自动浏览该列表,并将该文件另存为PDF列表中的每个人。
有没有可能像现在一样保存文件,然后自动将该文件发送到他们的电子邮件地址?
现在是我的代码:
Public Sub pdfopslag()
Dim myCell As Range
Dim valRules As Range
path = Range("I21").Text
Set valRules = Evaluate(Range("A9").Validation.Formula1)
Application.ScreenUpdating = True
Worksheets("factuur").UsedRange.Columns("A:G").Calculate
For Each myCell In valRules
emailadres = Application.WorksheetFunction.VLookup(Sheets("factuur").Range("A9"), Sheets("Gegevens").Range("A1:G6"), 7, False)
Range("A9") = myCell
filename1 = Range("B18").Text
filename2 = Range("A8").Text
PDF_File = path & filename1 & " " & filename2 & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:=PDF_File
On Error Resume Next
Set OutlApp = GetObject(, "Outlook.Application")
If Err Then
Set OutlApp = CreateObject("Outlook.Application")
IsCreated = True
End If
OutlApp.Visible = True
On Error GoTo 0
' Prepare e-mail with PDF attachment
With OutlApp.CreateItem(0)
' Prepare e-mail
.Subject = "test"
.To = emailadres
.Attachments.Add = PDF_File
' Try to send
On Error Resume Next
.Send
Application.Visible = True
If Err Then
MsgBox "E-mail was not sent", vbExclamation
Else
MsgBox "E-mail successfully sent", vbInformation
End If
On Error GoTo 0
End With
Next myCell
Set OutlApp = Nothing
End Sub
我只是不知道我需要推杆.attachments.add,因为现在它给出了错误440